Math bug or it is normal?

While working on a plugin i noticed a strange thing, if a subtract a number from 0.66 to 0.99 from 1, the result is not correct.


For example. 0.98 - 1 results in -0.020000000000000018, instead of -0,2. This can lead to some math mistakes, for example, if you do Math.abs((0.98 - 1) * 100), the result will be 3 instead of 2 (this was how i ended finding this issue).


This is a minor issue and is easy to solve (just multiply the values before the subtraction, as it seems only to happens with 0.66 to 0.99 - 1), but it is normal or is a bug from the maker?


Those who want to test it, just call console.log(x - 1) where x is a number between 0.66 and 0.99
It's normal. That happens because some float numbers can't be represented correctly in binary. Most languages automatically round numbers, but javascript doesn't, You can simply ignore anything after the 12th decimal place.


MVCommons adds the following method to do that:

Code:
Number.prototype.fix = function(){
  return (parseFloat(this.toPrecision(12)));
}

Original thread: https://forums.rpgmakerweb.com/threads/math-bug-or-it-is-normal.56461/