0,1 + 0,2 === 0,3 - FALSE [duplicated]

0
0.1 + 0.2 == 0.3
-> false

0.1 + 0.2
-> 0.30000000000000004

How can it be resolved so that 0.1 + 0.2 results in 0.3?

    
asked by àngelv 30.08.2017 в 11:17
source

1 answer

2

Put the result in a variable and ask ".Fixed (2)" to limit the decimals to 2.

var a = 0.1;
var b = 0.2;
var c = a.toFixed(2) + b.toFixed(2);
-> true
    
answered by 30.08.2017 / 11:20
source