Sure, but my point wasn't that it wouldn't fit in a 64-bit int (or even a 32-bit int). It's that "just work in cents" may be interpreted by "multiply by 100; do your arithmetic; divide by 100". That works if your currency is dollars or euros, and you're dealing with grocery prices. It doesn't get you out of the floating point numbers if you have amounts in mills. (And if you do "multiply by 100, round to nearest integer", you will be working with integers even if the amounts where in mills, but your results are likely to be off).
Just want to make people aware that "just work with cents" may in some cases a tad less simple that multiplying by 100. | [reply] |
Even with 5 decimal digits, a 64-bit int can represent 184 trillion, which in dollars is roughly 3 times the entire worlds gross domestic product for 2010. Should be good enough for the average Internet reseller for a few years. But those nice Nigerian bankmanagers who always propose me such lucrative deals, will run into problems and may in the end miss a few dollars left or right in their vaults. ;)
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
| [reply] |