4 ms·
There certainly are issues with precision: toFixed(1000.005, 2); // returns 1000.01 toFixed(1.005, 2) // returns 1 Rounding to a fixed number of f
by jansan 4y ago
There certainly are issues with precision:
toFixed(1000.005, 2); // returns 1000.01
toFixed(1.005, 2) // returns 1
Rounding to a fixed number of fraction decimals is extremely tricky, much trickier than it appears on first view.
This is beaten to death at Stackoverflow, but I can tell you that almost all (or all?) of the solutions provided don't work for all cases:
https://stackoverflow.com/questions/11832914/how-to-round-to-at-most-2-decimal-places-if-necessary/11832950#11832950 https://stackoverflow.com/questions/11832914/how-to-round-to...
- maccard 4y agoThis is an argument for having these fundamentals implemented in the language's standard library IMO.