goxarad784
goxarad784

Reputation: 435

Adding to a large number and return a non scientific notation number

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

Upvotes: 1

Views: 70

Answers (1)

Yousaf
Yousaf

Reputation: 29312

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 }));

Upvotes: 1

Related Questions