on 11/11/2003:
alert( 100 * 1.15 );
The above *should* show a value of 115. However, what I
am actually getting is:
114.99999999999998
alert( 100 * 1.10 );
is showing as:
110.00000000000001
Why?
Floating-point values are traditionally represented in a structure
with three parts: a mantissa, an exponent, and the sign. Each field
has a fixed size. Immediately, that suggests limits. Furthermore,
there are certain types of numbers that are difficult to represent
accurately. Basically, there are flaws, and there are plenty of
places to read about them on the Internet. This might not be quite so
true of JavaScript as it is with, say the FPU on a PC, but it's at
least a possible explanation.
Because of this, it's usually not a good idea to do direct
comparisons, and use ranges instead. Alternatively, round floating
point values at certain points in the computation or before
comparisons.
Mike