-3

Why the result of this data is doesn't give the exact value expected by a human brain or expected output of a person to appear

16.08 * 100 = 1607.9999999999998;

When i tried it to the console developer of the chrome browser;

and i tried using

console.log(16.08*100); gives 1607.9999999999998

Supposedly the answer that i should be seeing is

16.08 * 100 = 1608;

will you please help me with these. or any explanations

Oli Soproni B.
  • 2,774
  • 3
  • 22
  • 47
  • Floating point numbers are susceptible rounding errors. This is normal behavior. This is also why you should never strictly compare floating point numbers in Javascript, but should compare the difference of two floating point numbers relative to some threshold, like `abs(a-b) > .01` as opposed to `a == b`. – Alex Luecke Sep 08 '15 at 05:42
  • @AlexLuecke can you give me example on this "abs(a-b) > .01 as opposed to a == b" – Oli Soproni B. Sep 08 '15 at 05:46

1 Answers1

1

use .toFixed(n) method of javascript.

console.log((16.08 * 100).toFixed());
Md Ashaduzzaman
  • 4,032
  • 2
  • 18
  • 34