I'd go as far as to say that any value which may be displayed to the user should almost always be an integer. Money is only the most prominent example of this. Dealing 225 damage four times to a monster with 900 HP and finding that it still has 1 HP left will subtract from the experience just as much as finding that you are an invisible fraction of a penny short of affording something.
On the more technical side I think it's worth noting that one doesn't have to revert to floats to do advanced stuff like interest. As long as you have got enough headroom in your chosen integer type a multiplication and a division will stand in for a multiplication by a decimal number, for instance to add 4%, rounded down:
number=(number*104)/100
To add 4%, rounded by standard conventions:
number=(number*104+50)/100
No float point inaccuracy here, the rounding always split exactly on the .5
mark.
Edit, the real question:
###Edit, the real question:
SeeingSeeing how the debate has gone I start to think that outlining what the question is all about may be more useful than a simple int
/float
answer. At the core of the question it is not about data types, it's about taking control of the details of a program.
Using an integer to represent a non-integer value forces the programmer to deal with the implementation details. "What precision to use?" and "What way to round?" are questions that must be answered explicitly.
A float on the other hand does not force the programmer to worry, it already does pretty much what one would expect. But since a float is not infinite precision, some rounding will take place, and that rounding is pretty unpredictable.
What happens in one use floats and want to take control of the rounding? It turns out to be almost impossible. The only way to make a float truly predictable is to use only values that can be represented in whole 2^n
s. But that construction makes floats quite hard to use.
Thus the answer to the simple question is: If you want to take control, use integers, if not, use floats.
But the question that is being debated is just another form of the question: Do you want to take control?