0

I have a JavaScript long division program that prompts the user to enter a divisor and a dividend and also the number of decimal places to give the result in.

In JavaScript, when I divide the following I get the result:

60.30 / 5 = 12.059999999999999 

but using a calculator I get:

12.06

Is there an issue with JavaScript?

If I use toFixed that works in this instance, but if the numbers are as follows:

603.00000 / 55 = 10.96364 

where the calculator results in:

10.963636363636363636363636363636

I know that toFixed rounds the number but the rounding results in an incorrect answer on the second example.

Ian
  • 50,146
  • 13
  • 101
  • 111
Wesley Skeen
  • 7,977
  • 13
  • 42
  • 56

0 Answers0