O JavaScript possui várias condições decimais na operação de multiplicação de números de ponto flutuante.
Isso ocorre porque o número do ponto flutuante é convertido em binário após a operação, mas alguns decimais têm circulação infinita após codificação binária, o que causa erros na computação e há problemas semelhantes em outros idiomas.
A explicação da razão refere -se de Baidu para saber:
Por exemplo: 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 como um número de dígito decimal especificado.
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. redondo.
Copie o código do código da seguinte forma:
var m1 = 2232,00,
por cento = (10/100),
Total = por cento*M1;
alerta (total); // 223.20000000000002
Total = Math.Round (Total*10)/10;
alerta (total);