试图弄清楚功能上有什么问题?但是找不到什么问题
Sub test()
Dim a as double, b as double
a = "10,31"
b = "10,31"
Msgbox check(a,b)
End Sub
Function check(a as double, b as double)
ff = TypeName(a) ' double
gg = TypeName(b) ' double
If a= b Then GoodExVat = True Else GoodExVat = False: diffExVAt = b - a ' here a = 10,31 b=10,31 diffExVAt = -3.5527136788005-15
check = diffExVAt
End Function
如果a和b设为10,31,一切正常,但当10,31来自其他函数或表达式时,我得到了-3.5527136788005-15
答案 0 :(得分:2)
请勿在{{1}} - :
中使用It
,这有点令人困惑。如果你正常写它,它应该工作正常:
Else
关于调试 - 只需使用 F8 和逐步方法。
关于Sub Test()
Dim a As Double, b As Double
a = "10,31"
b = "10,31"
MsgBox check(a, b)
End Sub
Function check(a As Double, b As Double)
ff = TypeName(a) ' double
gg = TypeName(b) ' double
If a = b Then
GoodExVat = True
Else
GoodExVat = False
End If
diffExVAt = b - a ' here a = 10,31 b=10,31 diffExVAt = -3.5527136788005-15
check = diffExVAt
End Function
来自其他函数和表达式并获得10,31
,那么问题出在浮点数学中: