2

The following json with an integer in Firefox:

{"inventoryIds":15369683015733721}

parses the numeric value as 15369683015733720

This behavior has not been observed in other numeric values (so far).

To replicate: Save the json on disk and load in Firefox. The displayed value then looks like:

inventoryIds:   15369683015733720

Work around has been applied by just parsing the data as a string, which solves the issue, but the root cause would be nice to know.

(Same issue occurs in Chrome, tested on Linux (openSuse Leap, and Ubuntu 18.04LTS))

Norbert
  • 6,026
  • 3
  • 17
  • 40
  • Javascript stores numbers inside of 64bits, not every number fits into that. – Jonas Wilms Sep 16 '18 at 17:33
  • Your number is about 1.53e+16. The maximum safe integer value (number.MAX_SAFE_INTEGER) for javascript is 9007199254740991 (about 9e+15). So you're running out of large-numbers luck in javascript. Since it's an ID, its probably pretty safe to handle it as a string. – Arend Sep 16 '18 at 17:35
  • @Jonas I got to 9223372036854775807 for a signed 64bit. This is 1e3 larger than my value. However it turns out as indicated in the duplicate that the limit is a paltry 52bits. – Norbert Sep 16 '18 at 19:47
  • @norbert jup, only 52bit of those 64bit can be used as integer, the rest is the exponent – Jonas Wilms Sep 16 '18 at 19:48

0 Answers0