Why can a decimal-looking number change when serialized and read back?
Quick answer
Serialization turns a value into text; parsing that text creates a value according to the receiving system’s numeric type. In JavaScript, a number’s original spelling is not retained: trailing zeros can disappear, and sufficiently large integers can be rounded when parsed. If spelling matters, preserve the original text. If the numeric value matters, check whether every system can represent it with enough precision. [S1][S2]
The question, the details, the next step.
A practical checklist
Save the exact input text before parsing.
Decide whether numeric meaning, original spelling, or both must be preserved.
Check the parsed value in the receiving system and note its numeric type.
Compare serialized text separately from numeric value; look for changed zeros or notation.
Test large integers for exact digits, and keep precision-sensitive values as strings throughout.
A few more useful answers
Why might a number use scientific notation after conversion to text?
In JavaScript, Number.prototype.toString() uses scientific notation for magnitudes at least 10^21 or below 10^-6. That describes JavaScript Number formatting, not every serializer or language. [S2]
If I need the original decimal spelling, can I reconstruct it from the parsed number?
Not reliably in JavaScript: a Number’s text conversion represents its numeric value, not the original spelling, so details such as trailing zeros are not preserved. Keep the original text if those details matter. [S2]
Sources
References used for this guide.
- [S1] JSON — JavaScript | MDN developer.mozilla.org · Checked
- [S2] Number.prototype.toString() — JavaScript | MDN developer.mozilla.org · Checked
