JavaScript stores all numbers in double-precision floating-point format, with a 52-bit mantissa and an 11-bit exponent (the IEEE 754 Standard for storing numeric values), and therefore its Number-to-String conversions are often inaccurate. For instance,
111111111*111111111===12345678987654321
is correct, but
(111111111*111111111).toString()
returns "12345678987654320" instead of "12345678987654321". Likewise, 0.362*100
yields 36.199999999999996
.
Is there a simple way to accurately convert numbers to strings?