Possible Duplicate:
Large numbers erroneously rounded in Javascript
I am experiencing some strange behavior when working with numbers in javascript. When I use the following code:
<a href="javascript:console.log({'id':9200000000032337}.id);"> CLICK HERE </a>
I get the number 9200000000032336 in my console. I think it most be something with rounding or max values for numbers, but I don’t understand it completely. Anyone?
I’m not a Javascript expert, but it sounds like your number is being stored as an IEEE-754 64-bit floating point number. Certainly that’s what I get from C# code which will display the exact value of a
double:(Using my own
DoubleConverterclass.) My output is the same as yours: 9200000000032336Floating point values only ever hold a certain number of significant digits accurately – and when the numbers get high enough, even integers can’t be stored exactly.
ECMA-262 seems to confirm this:
and from section 7.8.3 (numeric literals):
Section 8.5 contains more details.