JavaScript has multiple decimal conditions at the multiplication operation of floating -point numbers.
This is because the floating point number is converted into binary after the operation, but some decimals have infinite circulation after binary coding, which causes errors in the computing, and there are similar problems in other language.
The reason explanation refers to from Baidu to know:
For example: 1038.1-1000
1038.1 = 10000001110.000110011001100110011001100110011001100 .....
1000 = 1111101000
1038.1 Converting into binary is an infinite cycle decimal. 1100 is the cycle. It can only take the approximate value. The error is that if the browser version is high here, you can use the TOFIXED () method to enter the number of number four as a specified decimal digit number.
Solution: Based on the decimal digits (such as 4) to be kept, first multiply (10^4) when calculating the product, then divide the calculation result (10^4), and finally take the result of the result value math.roundd.
Copy code code as follows:
var m1 = 2232.00,
percent = (10/100),
Total = Percent*m1;
alert(total);//223.20000000000000002
total = Math.round(total*10)/10;
alert(total);//223.2