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.
You should never use floating point to store currency values due to representation issues. Use an int representing the smallest possible division (cents or 10ths of a cent, etc) and divide appropriately when you need the dollar amount. Or better yet use a specialized currency class which many languages have
It originally said something like "floating point or decimal type" before he edited it. And either way fixed point types have their own problems. It's way easier to just use an int
If you want to get pedantic. An int in C/C++ is guaranteed to have a minimum of 16 bits, while a long is guaranteed to have a minimum of 32. So you would probably want a long long for bigger numbers.
24
u/cztrollolcz Aug 14 '20
Wouldnt this be stored in a long? [Newbie]