Previous | Next | (P-PDF) JavaScript
Topic: Desperate: Rounding and calculation mistakes Acrobat 4.X Win NT
Conf: (P-PDF) JavaScript, Msg: 104493
From: aandi
Date: 1/23/2004 08:31 PM
When working with money, as you've found, it's vital not to work with floating point numbers, because rounding errors just aren't acceptable.
You should convert all prices into cents (assuming your required precision is 1 cent) and work internally only in whole numbers. Every single arithmetic instruction that might result in a fraction must be rounded immediately to a whole number (you're OK with add, subtract and multiply by whole numbers). Think carefully in each case whether to round up, round down, or round to the closest number to reflect policies and/or legal requirements.
Then convert back to dollars and cents only at the instant the numbers are displayed.