Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parseInt changes the integer

I am trying to pull a number (72157648141531978), which starts at the 21st character, out of the title of a page like so:

parseInt(document.title.substring(21), 10);  

This returns the string as an integer of 72157648141531980. I can't seem to figure out why it is changing the last two numbers. Any help would be appreciated.

like image 578
metalfoley Avatar asked Nov 04 '25 20:11

metalfoley


1 Answers

According to What is JavaScript's highest integer value that a Number can go to without losing precision? the max value of an integer is 9007199254740992.

I tried your calculation on http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_parseint and I can confirm your problem.

It looks like an issue parsing beyond this max value and it is rounding the last 2 figures.

like image 142
Guy Lowe Avatar answered Nov 06 '25 21:11

Guy Lowe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!