Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Rounding problem?
Message
From
21/03/2000 09:59:59
Paul Frost
Instem Computer Systems Ltd
Stone, United Kingdom
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00348122
Message ID:
00348352
Views:
24
>If I remember my math , when rounding a number which is EXACTLY half way (in this case 0.0050000), the rounding rules get strange. For the round() function' I always add a five to the next decimal place to force the number to be rounded up. This removes erratic behavior of the ROUND function for numbers which fall exactly at the midpoint. For this case I would use :
>
>ln_round = .35000000 * 943.0 *.100
>ln_round = ln_round + .005 && Use .005 since we are ronding to two places
>ln_round = ROUND(ln_round,2)
>
>This will force any number which lands exactly midway to be rounded up. If you subtract .005 the midway number will be rounded down.

Shouldn't the operation here be truncation following addition of 0.005, otherwise this will always cause round up. Consider 1.0001, rounded to 2 dp this should be 1.00, if 0.005 is added, then calculation is round( 1.0051, 2 ) which should be 1.01, the wrong result.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform