Home >Web Front-end >JS Tutorial >js retains two decimal places using toFixed_javascript skills
Math.round(x*100)/100, of course what I want is Math.round(x*100), it doesn’t matter. But there is a problem with using Math.round(x*100) directly. Sometimes there is a small error, and many decimal places are displayed. For example, 0.9996*100 will become 99.96000000000001, which is not what I want.
Find the function of javascript, the number type has a toFixed() function, test: