1

I am trying to add 1 to a large number and return a non scientific notation value:

(parseInt("1000198078902400000000000000") + 1).toLocaleString('fullwide', { useGrouping: false })

However, this returns the same 1000198078902400000000000000 value instead of 1000198078902400000000000001 and I cannot figure out why

goxarad784
  • 395
  • 6
  • 17
  • 1
    Does this answer your question? [What is JavaScript's highest integer value that a number can go to without losing precision?](https://stackoverflow.com/questions/307179/what-is-javascripts-highest-integer-value-that-a-number-can-go-to-without-losin) – phuzi Oct 20 '20 at 14:59

1 Answers1

1

1000198078902400000000000000 is greater than the max integer value javascript can represent which is 253 - 1 that is equal to 9007199254740991.

You can use BigInt to get the desired output. BigInt can represent numbers that are larger than 253 - 1.

let num = BigInt("1000198078902400000000000000");
num += 1n;
console.log(num.toLocaleString('fullwide', { useGrouping: false }));
Yousaf
  • 27,861
  • 6
  • 44
  • 69