开发者

problem with vba macros code not equal to checking in decimal values

开发者 https://www.devze.com 2023-01-09 03:06 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号