problem with vba macros code not equal to checking in decimal values
In Macros coding, i am checking the not equal to condition. Values are in decimal or integer, Now i compare the two values in decimal values but not get the proper result. Please gu开发者_如何转开发ide me what is the thing should be added for getting corrected result?
My code is :
If fld4 <> fldval Then
MsgBox "....."
End If
But the output of message showing for the following values :
fld4 = 0.25, fldval = 0.26
fld4 = 0.25, fldval = 0.25
fld4 = 0.14, fldval = 0.14
fld4 = 0.11, fldval = 0.11
Never ever (!) compare floating point values directly. Better try something like this:
eps = =.00001 'choose an appropriate epsilon
If Abs(fld4- fldval)<eps Then
'...
Look here for further information.
精彩评论