javascript - Why does parsing a large number, of string form, give a larger number? -


this question has answer here:

see snippet:

var num = "9223372036854775808";  document.write(num);  document.write("<br>");  document.write(parseint(num, 10));

on running code snippet, first write yields:

9223372036854775808 

and third write yields:

9223372036854776000 

but, parsing number in string form number. why give still larger number?

i thought might have limits of storage capacity, then, why yield larger number if not store smaller?

i read question: why parsing large number integer return 1 , parseint doc did not much.

so, why parsing large number, of string form, return larger number?

the first result fine treated string.

in second one, crosses value of int +/- 9007199254740992 ie, maximum value parseint can parse 9007199254740992 , since value 9223372036854775808 larger maximum value. giving garbage value.

as commented correctly blunderboy seems that reason this

the numbers in javascript 64 bit "double" precision follow iee754 floating point. sothe largest positive whole number can therefore accurately represented 2^53 , rest of remaining bits reserved exponent.

if check ecma specs has been explained.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -