n = "11004691915666669"
parseInt(n)
parseInt(n, 10)
Both results are: 11004691915666668 This is off by one. I tested some other values and they convert correctly. Is this a bug in the library or is there a better way to convert?
n = "11004691915666669"
parseInt(n)
parseInt(n, 10)
Both results are: 11004691915666668 This is off by one. I tested some other values and they convert correctly. Is this a bug in the library or is there a better way to convert?
See this SO question for more details. Your value is beyond the maximum integer that Javascript can represent with full accuracy.
Under the hood Javascript doesn't understand integers, everything's floating point. You're hitting the reduced accuracy that happens when you get to very large numbers.
From the Javascript reference at MDN given here.
The integer range for a Number is defined as follows :
var biggestInt = 9007199254740992;
var smallestInt = -9007199254740992;
Which is why since your number exceeds the biggestInt value preset by Javascript, the parseInt method only returns the integer value that lies within the Integer range for a Number in Javascript as defined above.