Quote Originally Posted by Bill Brock View Post
This may be fodder for another post but it is another document issue.

a1: 5.51% percentage, auto decimal
a2: 6.68% percentage, auto dec.
a3: 7.54% percentage, auto dec.
a4: 19.72999999999... sum a1,a2,a3, percentage, auto decimal

a4 should be 19.73% instead of the 19.729999999... If I force 2 decimals it rounds up to the right answer so I wasn't that concerned. But this is straight addition and the sum is wrong.
This is one of the funniest JS bugs. Execute this code i.e. in Firebug console, or anywhere:

alert(5.51 + 6.68 + 7.54);

It says 19.73. Now try this one:

alert(7.54 + 6.68 + 5.51);

It says 19.729999....97! :-)

The thing is, we compute sums in reverse order as it turns out to be slightly faster.

You can search the web for "javascript floating point bug" and it'll reveal lots of info about it. Unfortunately, I don't see what we could do... In this particular example, we can "fix" by changing the order in which we compute the result, but as you can imagine, it won't help a dime for the general case.

It gets fixed indeed if you manually restrict precision.