Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
IF Statement Doesn't Seem to be Working
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00123956
Message ID:
00124373
Views:
21
>No problem! How about on your pc contributors? Try it and see...

Jeff,

because it wokrs on your machine does not discount the fact that numerics are converted from a character string in the dbf to an binary number in memory. That conversion can cuase a number that looks and acts like 0 to really be 0.00000001 and using the equal sign will say they aren't the same value.

This can happen for a variety of reasons. The solution to prevent it form ever biting you is to avoid the = operator for comparing numbers especially wehn one is a field in a dbf and the other is in memory. In prior version there was bug (which has been fixed) that cause an index on a numeric field to fail on a seek for a value that for purposes was in the table.

In the example situatio in this thread the solution sits in comparing for a range of values that would be considered 0. If the numeric field has 2 decimals then;

IF Field < 0.01

If it might be negative;

IF Field < 0.01 and Field > -0.01

These IF's side step any binary rounding problem.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform