fetch() response truncating big numbers fetch() response truncating big numbers json json

fetch() response truncating big numbers


It has to do with the number of digits of precision in JavaScript. In JavaScript, all numbers are stored as floating-point, which is like scientific notation in base 2 instead of base 10. There is a fixed number of bits (53 in this case) available to represent a in a * (2 ** b). If you look at Number.MAX_SAFE_INTEGER, the greatest integer that can be represented with 53 bits of precision, you will see that it has 16 base-10 digits. Your number has 19. If you just type the number into a JavaScript console, you will see that it prints out the rounded version (with 16 digits of precision). If you need to be storing such large numbers, it is usually best to store them as strings.