Home > Article > Web Front-end > Summary of rounding methods in javascript_javascript skills
The rounding function toFixed(n) in native javascript, n is the number of decimal places to be retained. (0<= n <=20)
The output value is not the expected 1.0999, but 1.09990000000000009983. This needs attention, and the reason needs to be improved.
In addition, in different browser versions, if the decimal point and the previous digit to be intercepted are both 0, interception may not follow common sense.
http://jsfiddle.net/ogwnw2j3/
Value may be 0.0
The method of processing is to add 1 before using the toFixed method, and then subtract 1 after using it.