0

I've got the following problem when i'm counting in javascript.

var processAmount = parseFloat(166.98) - parseFloat(61.58);

The result is: 105.39999999999999

Doesnt matter if I use parseFloat() or not.

How can I solve this?

DontVoteMeDown
  • 20,534
  • 10
  • 70
  • 102
Leon van der Veen
  • 1,588
  • 10
  • 41
  • 58

1 Answers1

0

Sometimes floats numbers cannot be represented exactly in binary.

Try this:

var processAmount = parseFloat(166.98) - parseFloat(61.58);
processAmount.toFixed(2);

FROM: Javascript float subtract

Community
  • 1
  • 1
giordanolima
  • 1,150
  • 1
  • 12
  • 19