Updates:
Status: WorkingAsIntended
Cc: [email protected]
Comment #1 on issue 1525 by [email protected]: v8 can't convert number
to string correctly even if the number is a 43bit precision integer.
http://code.google.com/p/v8/issues/detail?id=1525
Precise representation of this number requires 57 bits not 43.
When formatting a string representation of double we are free to choose any
string that when parsed back would give the same double number. Simply
speaking only the following must hold:
parseFloat(d.toString()) == d
In this case both 76287755398823940 and 76287755398823936 map to the same
double number and we can use either of them when printing the result back.
You can use d.toFixed(0) to uses different formatting algorithm for numbers
less than 10^21. This algorithm will render double with mantisa m and
positive exponent p exactly as integer m*2^p. In you case it means that
(76287755398823936).toFixed(0) === "76287755398823936"
For more information please read:
ECMA-262 5th 9.8.1 ToString Applied to the Number Type.
http://es5.github.com/#x9.8.1
ECMA-262 5th 15.7.4.5 Number.prototype.toFixed (fractionDigits)
http://es5.github.com/#x15.7.4.5
Details about the algorithm used by V8 are available in Florian Loitsch's
paper "Printing Floating-Point Numbers Quickly and Accurately with
Integers".
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev