我想使用 vb.net 对小数进行基本计算。
Dim a As Single= 7200.5
Dim b As Single= 7150.3
Dim c As Single= a - b
'Expected result = 50.2
MsgBox(a.ToString + " - " + b.ToString + " = " + c.ToString.Trim)
'Produced result is: 50.2002
Dim single1 As Single
Dim single2 As Single
Dim single3 As Single
single1 = 425000
single2 = 352922.2
single3 = single1 - single2
'Expected result is: 72077.8
MsgBox(single3.ToString)
'Produced result is: 72077.81
如此简单的计算结果怎么会如此不准确?当我将数据类型更改为 时,问题得到解决Decimal
,但Decimal
对象消耗更多内存(16 字节)。是否有任何替代数据类型可用于执行简单的分数计算并获得准确的结果?