[Vuejs]-Why is Firestore rounding numbers of 16+ digits?

0👍

Just like the other question, your number is exceeding the size of a JavaScript number, which is a signed 53 bit number. Firestore is capable of storing up to 64 bits, and if you try to read the number back in JavaScript or view in the console, you will lose data. (The issue is not the number of digits, it’s the magnitude of the number with respect to the max number of bits available to store it internally.)

Numbers that start with 0 always lose leading zeroes when written to any pure number store. Leading zeroes are meaningless for the purpose of computation, so they are dropped from the representation. If you want to display leading zeroes for whatever reason, you should format the number as a string and pad the zeroes before printing it.

If you want to store a formatted number without losing any of its formatting, or if you want to store something bigger than 64 bits, you should store it as a string type field instead of a number. But then you will lose the ability to perform rational mathematical comparisons on it in your queries.

Leave a comment