日期:2011-04-10  浏览次数:20432 次

 

---VB.NET Single & Double---
single的精度的问题
先简单说明一下:项目里面有个金额的内容,一开始使用的single,后来发现只有金额在(-100000.66,1000000.66)区间中才能真实的储存对应的值,测试了一下代码如下:
    小数点后第二位6开始进位,例如100000.66成为100000.7

1Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
2        Dim a As Single
3        a = TextBox1.Text
4 Label1.Text = a
5    End Sub

改成Double:
测试成功

1    Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
2        Dim a As Double
3        a = TextBox1.Text
4 Label1.Text = a
5    End Sub

所以金额的类型要设为Double,咳咳.
---end---