3 ms·
Either return cents (for decimal currencies), or more generally create a "currency" type with ints and conversion ratios for each "field" (for example a "US Dol
by Intermernet 11y ago
Either return cents (for decimal currencies), or more generally create a "currency" type with ints and conversion ratios for each "field" (for example a "US Dollar" type would have "dollars" and "cents", with ratios of "1" and "100". This means you can handle non-decimal currencies[1] like the Malagasy Ariary[2] and the Mauritanian Ouguiya[3] (1 ariary = 5 iraimbilanja, 1 ouguiya = 5 khoums)
As you said, easier said than done; but you really don't want FP errors popping up in financial calculations :-)
[1]: https://en.wikipedia.org/wiki/Non-decimal_currency https://en.wikipedia.org/wiki/Non-decimal_currency
[2]: https://en.wikipedia.org/wiki/Malagasy_ariary https://en.wikipedia.org/wiki/Malagasy_ariary
[3]: https://en.wikipedia.org/wiki/Mauritanian_ouguiya https://en.wikipedia.org/wiki/Mauritanian_ouguiya