Javascript toFixed(2) function not working

I am trying to get an output of 4.01 but I am getting 4.013000000000005 instead. The first time I ran the code, I thought the problem was that I didn’t have parseFloat but it still doesn’t run. This is the code:

var num = 194.092;
var amount = 198.103;
console.log(amount - parseFloat(num.toFixed(2)));

85 thoughts on “Javascript toFixed(2) function not working”

Leave a Comment