Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What is a more accurate way to round numbers than Round(
Message
De
18/09/2003 03:01:18
 
 
À
17/09/2003 17:09:51
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00830026
Message ID:
00830199
Vues:
25
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform