5 ms·
You don't use floats for money, because it's an integer.
by Gordonjcp 3y ago
You don't use floats for money, because it's an integer.
- taeric 3y agoOddly, money is not an integer at large scales. At least, if you meant to calculate it in pennies, that doesn't work. Consider, what is the cost of gas?
- sweetjuly 3y agoI'm not quite sure what you mean? In most any case I can imagine, uint64 is quite enough to count money in pennies, assuming inflation doesn't get truly out of hand.
- taeric 3y agoGas is priced in sub penny values. Similarly, returns and other values are all typically calculated in sub penny values. You could store in 1/100th of a penny, I suppose? I'm not entirely sure that will work out for all calculations.
- Gordonjcp 3y agoAt present? Price at the pump is 72.9 pence per litre, which is represented internally in the software as 7290 1/100ths of a penny.
- taeric 3y agoRight, my point was just that "use pennies" won't work. You have to use fractions of a penny for different tasks. I'm not sure on the implications of using different fractions at different levels, but I'm sure the problem is more complicated than it sounds. Even before you get into the various methods of rounding that exist.