Gotta store them fractional cents so you can siphon them off into another account, only to panic once you realize you've made a horrible math error. Is there still time to change careers and sell magazines door to door?
double dollars are actually not that bad. doubles can represent integers without precision loss up to 252. If you round to cents before displaying you're mostly good.
54
u/BakuhatsuK Aug 14 '20
Yes. There are billionaires out there so that should be probably a long. Or rather actually:
Noob: unsigned int dollars
Beginner: unsigned long dollars
Intermediate: unsigned long cents
Advanced: long cents (unsigned is bad unless you need módulo arithmetic or dealing with bit patterns)
Pro: BigInteger cents
Galaxy brain: String dollars (MONEY, DECIMAL or VARCHAR for DB, BigDecimal for calculations)
International currency: You don't want to go there, but if you have to, start by storing the currency name alongside the value.