Comparing numeric values not as expected (VBScript)

42 Views Asked by At

I stumbled upon a strange behavior of VBScript when comparing numerical values. I expect it's a rounding issue but I can't figure out how I can improve the code to behave as expected.

Dim angle

angle = 3.55*180.0/3.55
MsgBox CheckValue(angle)        ' returns True

angle = 3.56*180.0/3.56
MsgBox CheckValue(angle)        ' returns False (unexpected!)

Function CheckValue(input)
    Dim check
    check = False
    If input = 180.0 Then check = True
    CheckValue = check
End Function
0

There are 0 best solutions below