How to increase this number(you can try it on the browser console):
36893488147419103000 + 1
The result of this is:
36893488147419103000
The number stays the same no changes to it why is that? and how can I increase it by 1?
How to increase this number(you can try it on the browser console):
36893488147419103000 + 1
The result of this is:
36893488147419103000
The number stays the same no changes to it why is that? and how can I increase it by 1?
For big integers you should use the BigInt (Big Integer) type.
Note 1: you almost always cannot mix BigInt
numbers with Number
s (eg for math operations) without first performing an explicit conversion.
Note 2: JSON does not currently natively support BigInt
values. As a workaround you can use strings (eg. '1n' for the values and then use a reviver function when calling JSON.parse
.
JavaScript currently only has two numeric types: double-precision IEEE 754 floating point Number
s, and Big Integers which can be used to represent arbitrarily large integers. You can declare a BigInt
number literal using the suffix n
, eg. 1n
.
IEEE 754 Number
s can "only" accurately represent integers up to and including Number.MAX_SAFE_INTEGER
, which has a value of 2^53 - 1 or 9,007,199,254,740,991 or ~9 quadrillion.
From MDN:
Double precision floating point format only has 52 bits to represent the mantissa, so it can only safely represent integers between -(253 – 1) and 253 – 1. "Safe" in this context refers to the ability to represent integers exactly and to compare them correctly. For example,
Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2
will evaluate to true, which is mathematically incorrect. SeeNumber.isSafeInteger()
for more information.
A "Decimal" number type, that will be able to represent arbitrarily precise decimal numbers, is under development.
Double precision floating point format only has 52 bits to represent the mantissa, so it can only safely represent integers between -(253 – 1) and 253 – 1. See Number.MAX_SAFE_INTEGER. Larger numbers may not be able to be represented exactly.
Obviously the number is internally represented as a floating point number.When the value you want do add to this number is less then the value of the least significant bit, it will not change the the value. The only way would be to use floating point numbers with a higher resolution i.e. with a higher number of significant bits.