-1

excuse me if this common question or newbie question..

i am wondering why JS calculation return wrong result, i have calculation like this

console.log(((11000 * 100) / (100 + 1) * 1) / 100);

when i using calculator it returns 110, but when i calculate using JS it returns 108.91089108910892

here's the example:

console.log(((11000 * 100) / (100 + 1) * 1) / 100);

are there way to fixed this? or i am wrong doing the calculation? i have try .toFixed() method but that's not what i want..

nb: i have read this solution but that is just rounding up the value not the result (mine is far different 110 to 108.91089...)

Yosafat Ksatria
  • 133
  • 1
  • 1
  • 14

2 Answers2

1

The calculation is right

Here is how it actually looks

        (11000*100)
       ------------
         (100+1)*1
   _____________________
            100

The above translates to

       1100000           1
     ---------    X   ------
        101             100

Do this calculation following BODMAS rule and the result is 108.91(approx)

brk
  • 48,835
  • 10
  • 56
  • 78
0

When converting .1 or 1/10 to base 2 (binary) get a repeating pattern after the decimal point, just like trying to represent 1/3 in base 10. The value is not exact, thus don't make use of common floating methods.

Charles
  • 52
  • 7