function myFunction() {
var c = parseFloat("10.81") +parseFloat("10.00");
alert(c);
}
//output is 20.810000000000002 why?
function myFunction() {
var c = parseFloat("10.81") +parseFloat("10.00");
alert(c);
}
//output is 20.810000000000002 why?
You can use toFixed
to get the precision to two digit floating number. In that case you will get the desired result:
function myFunction() {
var c = parseFloat("10.81") +parseFloat("10.00");
alert(c.toFixed(2));
}
//output is 20.810000000000002 why?
myFunction();