This is not toString and valueOf , which truncates trailing 0s after the decimal number!
When you write a decimal as follows:
var num2 = 0.0100
you tell your interpreter that the variable num2 should contain the decimal number 0.0100, i.e. 0.01, since the last two zeros are not significant.
A decimal number is a memory represented as a decimal number:
0.0100 0.010 0.01 0.01000
- all are the same number, and therefore they are all represented equally in memory. They cannot be distinguished.
Thus, it is impossible to find out if num2 is assigned a value of 0.01 by writing this number with zero, one, two or more trailing zeros.
If you want to save the decimal number as it is written, you must save it as a string.
source share