Comment #4 on issue 522 by [email protected]: toFixed() method problem
http://code.google.com/p/v8/issues/detail?id=522

The problem here is that IEEE 754 floating point numbers are not compatible with basic math, or rather, not with basic math on decimal numbers.

When you write "0.95" in normal math, the sequence of characters represents exactly the value 95/100. Rounding that will give 1.

When you write "0.95" to represent a 64-bit double precision number, which is what number literals in JavaScript do, the actual value it represents is 0.94999999999999996, which rounds to 0.9 with one decimal digit.

Double numbers are represented by a fixed number of *binary* digits, which has the consequence that not all decimal values can be represented - just as not all values can be represented by a finite number of decimal digits (e.g., 1/3).

The value 0.94999999999999996 is the closest representable value to 95/100.



--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to