Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What is a more accurate way to round numbers than Round(
Message
From
18/09/2003 03:01:18
 
 
To
17/09/2003 17:09:51
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00830026
Message ID:
00830199
Views:
26
Sometimes, when you get floating-point errors due to compound calculations or aggregating functions in SELECT - SQL, you need to check if two numbers are "close enough" to each other (i.e. within a certain tolerance), rather than exactly equal.
FUNCTION CloseEnough

LPARAMETERS ;
    tnFirstNumber, ;
    tnSecondNumber, ;
    tnPercentTolerance

RETURN ;
    tnFirstNumber / tnSecondNumber >= (1 - (tnPercentTolerance / 100)) ;
    AND tnFirstNumber / tnSecondNumber <= (1 + (tnPercentTolerance / 100))
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform