The problem here, is that the computer, works
internally in a different number system called the
binary number system, and there's no exact representation
for 4.35 in that system. It's kind of
similar to your pocket calculator. When you divide
ten by three, you get 3.3333 and so
on. And then when you multiply again with
three, you would get 9.999999 and so on.
And the reason is that there is no
exact representation for the fraction ten over three
in the decimal system. Now as programmers, we
don't usually worry about the detail reasons why these
round of errors occur, we just have the
general intuition that floating point numbers are a little
bit fuzzy. Just like the fuzzy photo over
here, you can't quite rely on every last pixel.
So when you get a number like 434.999 and
so on, that's just something we have to deal with.
Now, in this case, if we don't want to
lose any pennies, the remedy would be to use integers
and work in pennies. If this had been 435
pennies as an integer, a 100 times 435 would not
have been a problem. There are several other number
types in Java that you may need in more technical
situations, we've prepared a fact sheet for you. Go ahead, read through
the worksheet, and then work with Sarah on a few quiz questions