Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Rounding algorithm?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00313184
Message ID:
00313326
Vues:
36
Thanks to Paul M, Ed R. and Peter F. = all three methods work fine - I chose Paul's because it is the shortest

thanks!
Ken


>>Hi,
>>
>>Does anyone have a good algorithm for rounding a number (money) to the nearest 50 cents, 75 cents, etc? I'm trying to avoid breaking it down into integer and decimal components and running through a case statement. I'm hoping for some slick one or two line UDF.
>>
>>thanks!
>>Ken
>
>OK, I'll give it a shot. How about:
>
>
>FOR lnCount = 1 TO 5 step .01
>   ? ALLTRIM(STR(lnCount,6,2)) + " Rounded: " + ALLTRIM(STR(RoundQtr(lnCount),6,2))
>ENDFOR
>
>
>FUNCTION RoundQtr()
>LPARAMETER lnAmount
>LOCAL lnRoundedAmt
>
>lnRoundedAmt = .25 * (ROUND(lnamount/.25,0))
>
>RETURN lnRoundedAmt
>
>
> It seems to work OK.
Ken B. Matson
GCom2 Solutions
Répondre
Fil
Voir

Click here to load this message in the networking platform