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
  • 21,122
  • 10
  • 69
  • 105
Leon van der Veen
  • 1,652
  • 11
  • 42
  • 60

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,190
  • 1
  • 12
  • 21