Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to fix rounding bug
Message
From
04/10/2007 04:46:33
 
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01258001
Message ID:
01258432
Views:
21
>You can create your own function RoundEx and do global replace for 'ROUND(' with 'RoundEx('.
>
>* Sample code, no error handling or parameters checking
>FUNCTION RoundEx(tnNumber, tnRoundTo)
>RETURN ROUND(ROUND(tnnumber, tnRoundTo+2), tnRoundTo)
>
Thank you.
CREATE CURSOR test( KOGUS   N(12,4), KAUBASUMMA N(15,5), kogpak n(9,4) )
INSERT INTO test VALUES ( 1, 5.51031, 16 )
MESSAGEBOX( ROUND( ROUND(kogus*kogpak*kaubasumma,4),2) )
Observed: 88.17
Expected: 88.16

So ROUND( ,4) is not solution.
Round(,5) work in both cases. However, it may work in some other cases.
So round(, n+x) is not solution.

Any idea how to fix this ?
How to create function which rounds properly ?
SBT wrote white paper about VFP rounding bugs and they wrote custom rounding function in FLL. However I do'nt remember where to find this.
Andrus
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform