0

I have a very wired problem with numbers in javascript. Some big numbers return the wrong value. Here a few examples

let number = 23020678097666048;

console.log(number); // Output is 23020678097666050
console.log(number + 4) // Output is 23020678097666052
console.log(number + 5) // Output is also 23020678097666052

Is it possible that the number is too big? Can anyone explain the behavior to me?

Markus
  • 1,909
  • 4
  • 26
  • 54
  • 1
    The answers flagged as duplicate are all wrong and relate to floating point math, the real duplicate of this question is: https://stackoverflow.com/questions/307179/what-is-javascripts-highest-integer-value-that-a-number-can-go-to-without-losin Long story short, your number is too big. – mhodges Feb 24 '20 at 19:35
  • Javascript does have some BigInt stuff coming. let number = BigInt(23020678097666048); number + BigInt(4) – Matt Feb 24 '20 at 19:40
  • 1
    @mkaatman: Rather: `23020678097666048n + 4n`. – Felix Kling Feb 24 '20 at 20:10

0 Answers0