4 ms·
Money is always funny to represent. I did a bunch of research on this for my budgeting app. Turns out that while most countries use two decimal points for their
by IgorPartola 8y ago
Money is always funny to represent. I did a bunch of research on this for my budgeting app. Turns out that while most countries use two decimal points for their cent/cent equivalent, some use 0, 1, or 3. In addition, at least one country (Sweden I think), doesn't allow values like 0.01. Their smallest denomination is 0.05, and everything is a multiple of it. I ended up storing the data as a decimal type with 3 digits after the decimal, along with the currency. Then I periodically extract the locale data from a Linux timezones package and the app has a giant lookup table for how to represent and parse each currency + value combo. This changes from time to time as currencies get updated and governments change.
- emptyfile 8y agoAs someone who does a lot of work in payroll (in eastern europe...) the swedish system sounds like a dream.
- paulddraper 8y agoWhy?
- rb808 8y ago> In addition, at least one country (Sweden I think), doesn't allow values like 0.01. There are a few countries where they no longer bother with small coins to represent .01, so cash transactions are rounded to nearest .05 or similar, but the .01 is still valid for electronic transactions. I expect that is the situation in Sweden. (I wish US did this too)
- kentosi 8y agoAnd Australia. We got rid of 1c and 2c coins back in the 90s.
- axman6 8y agoBut electronic transactions are still processed to the cent.
- Mister_Snuggles 8y agoCanada did this. No more $0.01 coins, $0.05 is the smallest denomination. Electronic transactions, which account for over 50% of transactions in Canada, still use pennies though.
- manojlds 8y agoIndia got rid of 0.1, 0.25 and 0.5. Cash transactions are rounded to the rupee.
- daxterspeed 8y agoAll electronic transactions handle the SEK cent (1/100 SEK aka öre) though there are no longer any valid SEK cent coins. The 50 cent coin was taken out of circulation September 30th 2010 and nowadays all remaining cent coins are considered scrap metal. There's (sadly) no rule that everything must be a denomination of 0.05 SEK or even 1 SEK. Pretty much every shop continues to use cents in their pricing (like .50, .95, and .99). If you pay in cash you'll end up rounding to nearest SEK (rounding up if it's below 1 SEK). You could potentially save money by paying with cash if your transaction would be rounded down... but at a maximum of 0.49 SEK (~0.05 USD) saved per transaction you'd need some unique spending habits to actually utilize this "trick" efficiently. Source: https://www.riksbank.se/en-gb/payments--cash/notes--coins/coins/invalid-coins/ https://www.riksbank.se/en-gb/payments--cash/notes--coins/co... and I happen to be Swedish.
- bloemy 8y agoSwitzerland only has 0.05 as a minimum denomination too, might be the one you were thinking about.
- axman6 8y agoThe Haskell library safe-money does a great job of handling these weird cases for currencies. It has a separation between the types used for calculations and storage/presentation, and lets you define arbitrary ones so in your example you can handle computations in an arbitrary precision rational representation and then store it in cents and later convert with proper rounding to 5 cent increments if necessary. Much of this is handled by the type system, including type safe currency conversion.