我正在做一个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
我无法理解,有人可以帮助我吗?
答案 0 :(得分:1)
将.
添加到字符串然后转换它。
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
答案 1 :(得分:1)
根据答案的类型,你真的希望这两个陈述中的一个应该做得很好:
Dim Answer As Double = CTYPE(Textbox1.Text & "." & Textbox2.Text, Double)
或
Dim Answer As Decimal = CTYPE(Textbox1.Text & "." & Textbox2.Text, Decimal)
答案 2 :(得分:0)
只需添加“ 0”即可。在文字前面:
Dim assd As String = "9998"
dim ans as string
ans = "0." & assd