Note that all the third-party big-integer/big-decimal libraries are complicit. `new Decimal(1e23)` will get you a `Decimal` with exact value 100000000000000000000000
-
-
Show this thread
-
In the past I've raised bugs about this but apparently switching over to the correct behaviour would be counterintuitive and break backwards compatibility
Show this thread -
In the end I developed a module to do this (among other things) https://github.com/qntm/precise-json … > require('precise-json').stringify(0.1) '0.1000000000000000055511151231257827021181583404541015625'
Show this thread
End of conversation
New conversation -
-
-
FWIW, calling toString on the number with a radix other than 10 gives an exact value, and should be cross-browser compatible. If you want a decimal value, you can do that and convert, or do iterated modulus and divide.
-
The `toString(2)` approach is a good shout but I found it stops working for some values. E.g. `Number.MIN_VALUE` is non-zero but `Number.MIN_VALUE.toString(2)` returns "0"
- 7 more replies
New conversation -
-
-
This Tweet is unavailable.
-
The number 1e23 does not exist in JavaScript. The programming language is silently lying about what it does at source code parse time, and then lying again at log output time. I have an essay on this topichttps://qntm.org/notpointthree
- 3 more replies
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.