doubles
aren't kept in decimal internally, but in binary. Their storage format is equivalent to something like "100101
multiplied by 10000
" (I'm simplifying, but that's the basic idea). Unfortunately, there's no combination of these binary values that works out to exactly decimal 0.01, which is what the other answers mean when they say that floating point numbers aren't 100% accurate, or that 0.01 doesn't have an exact representation in floating point.
There are various ways of dealing with this problem, some more complicated than others. The best solution in your case is probably to use int
s everywhere and keep the values in cents.