0

I'm sure this has something to do with floating point math or something, but I need to out how to correctly interpret this number 9703248444284653. Javascript apparently doesn't like it

If I just do this.

var test = 9703248444284653
console.log(test)

The result is 9703248444284652, which is obviously not correct. Problem is that 9703248444284653 is an id that can't be changed. I have no idea what to do with this.

hobberwickey
  • 6,118
  • 4
  • 28
  • 29

1 Answers1

0

Your value is larger than Number.MAX_SAFE_INTEGER.

console.log(9703248444284653n > Number.MAX_SAFE_INTEGER);

You should treat your IDs as BigInt values. So you can should probably store the values as strings and then parse them as BigInt values if you need to perform any math on them.

const
  bigIntNative = 9703248444284653n,
  bigIntConstructed = BigInt('9703248444284653');

console.log(typeof bigIntNative === 'bigint' && bigIntNative === bigIntConstructed);

console.log(`${bigIntNative}`);
Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132