我在做一个vb计算器,我有两个文本框,一个是整数,另一个是小数部分。在小数部分文本框中输入时,需要以整数形式输出。
for example: i text 9998 into decimal part text box should actually be 0.9998.
so when i am doing a addition, i need to convert 98 to 0.98 to do the calculation
我想不通,有人可以帮助我吗?
我在做一个vb计算器,我有两个文本框,一个是整数,另一个是小数部分。在小数部分文本框中输入时,需要以整数形式输出。
for example: i text 9998 into decimal part text box should actually be 0.9998.
so when i am doing a addition, i need to convert 98 to 0.98 to do the calculation
我想不通,有人可以帮助我吗?
根据答案的类型,您真的希望这两个陈述之一应该做得很好:
Dim Answer As Double = CTYPE(Textbox1.Text & "." & Textbox2.Text, Double)
或者
Dim Answer As Decimal = CTYPE(Textbox1.Text & "." & Textbox2.Text, Decimal)
添加.
到字符串然后转换它。
Private Function ToDecimalFromString(str As String) As Decimal
Dim temp As String = String.Format("{0}{1}", ".", str)
Dim dec As Decimal
Decimal.TryParse(temp, dec)
Return dec
End Function
只需添加“0”。在文字前面:
Dim assd As String = "9998"
dim ans as string
ans = "0." & assd