0

Javascript says 0.7-0.2 is equal to 0.49999999999999994.

The case is the following:

var change = 0.7 - 0.2;

switch (change) {
    if (change.toFixed(2) >= 1) {
        ...
    }
    else if (change.toFixed(2) >= 0.50) {
        ...
    }
    else if (change.toFixed(2) >= 0.20) {
        ...
    }
    ...
}

By using .toFixed() method, the problem is solved but is there another way, instead of using .toFixed() n-times;

  • Argh, this is probably more relevant: [How to deal with floating point number precision in JavaScript?](https://stackoverflow.com/q/1458633) – VLAZ Apr 06 '20 at 14:04
  • @T.J.Crowder could you please also add the other link I posted? I think it's more relevant here. – VLAZ Apr 06 '20 at 14:05
  • @VLAZ - Already had done. :-) I marked the dupe with the other but went looking for that (wish I'd seen your comment!), as it's the "what to do about it" part of this. – T.J. Crowder Apr 06 '20 at 14:05
  • @T.J.Crowder thanks a bunch anyway. I meant to link the "how to deal" but I copied the wrong URL and didn't check when pasting. – VLAZ Apr 06 '20 at 14:08

0 Answers0