-4

In my console browser, I put:

666.66/10

And I get:

66.666

(As expected). But when I put:

6666.66/10

I get:

666.6659999999999

Can someone explain me why this happen? It shouldn't be: 666.666 ?

amp
  • 11,754
  • 18
  • 77
  • 133

1 Answers1

2

Computers don't store numbers in base 10, like we think - it's in base 2, so oddities like the one you've found are common.

Another one is 0.1 + 0.2, which counter intuitively equals 0.30000000000000004

If you want to safely divide numbers, either convert them to whole numbers first or use a library like BigDecimal

SomeKittens
  • 38,868
  • 19
  • 114
  • 143