0

I have a very very straight forward math problem that is being done. The problem is JavaScript is telling me the wrong answer. After doing some reading, it is related to the https://en.wikipedia.org/wiki/Floating_point and https://en.wikipedia.org/wiki/IEEE_floating_point

However I do not know how to fix the problem really simply.

V = 118.3;
X = 22;
Y = 0.05;

z = (X * Y) + V;

In this case the answer should be 119.4 but JavaScript is telling me it's 119.39999999999999.

I have been looking but I can not seem to come up with a solution. Does anyone know how to fix, stop, predict, etc this weird "bug" of JavaScript?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Pyromanci
  • 527
  • 9
  • 21

0 Answers0