1

I countered this issue in my program, I have a string numStr and I want to parse it as an integer.

I tried both on node and spider-monkey environments.

What is the problem and how I fix it?

const numStr = '12360600901222567';
console.log(+numStr);
console.log(parseInt(numStr));
console.log(parseFloat(numStr));
console.log(Number(numStr));

Output:

12360600901222568
12360600901222568
12360600901222568
12360600901222568

Expected:

12360600901222567
Dennis Vash
  • 50,196
  • 9
  • 100
  • 118
  • 3
    `12360600901222568` is greater than `Number.MAX_SAFE_INTEGER` - though, in node (and Chrome) there is `BigInt('12360600901222567')` – Jaromanda X Oct 18 '18 at 10:41
  • Check this https://stackoverflow.com/questions/307179/what-is-javascripts-highest-integer-value-that-a-number-can-go-to-without-losin – Cata John Oct 18 '18 at 10:42

0 Answers0