0

I don't get why javascript math lib calculate some wierd value when doing such simple math operation as (more examples in the fiddle) http://jsfiddle.net/ye9amc2k/

16.99 + 21 = 37.99 ? not for javascript ! (37.989999999999995)
16.98 + 21 = 37.980000000000004 ...

Is it some rounding problem ? a type one (int vs float) ? a browser one (i'm using chrome right now) ?

ToXinE
  • 308
  • 2
  • 13
  • 1
    JavaScript numbers are always floating-point numbers. – Pointy Dec 09 '14 at 17:52
  • 1
    This is how computer handle floating point numbers. It can become quite complex, but a computer cannot perfectly add two decimals and output the exact value without further arithmatic as some libraries like Math.js incorporate. – Tai Kwangi Chicken Dec 09 '14 at 17:53

0 Answers0