5 ms·
Why not just represent different currencies as different "types" and a quantity of their basic unit (cents for $, pennies for £, tambala for Kwacha) and have st
by robert_ 11y ago
Why not just represent different currencies as different "types" and a quantity of their basic unit (cents for $, pennies for £, tambala for Kwacha) and have standard conversions between them:
kwacha_t my_kwacha = 100000; // 1000 Kwacha
euro_t my_euro = EU_from_kwacha(my_kwacha);
printf("My Kwacha in Euros: %d", my_euro / 100);
Most of the problems discussed seem to resolve around trying to have some universal monetary unit, which isn't possible in practice anyway. Just settle on a universal currency for international trade (as the $ effectively is) and convert from/to as necessary for local representation.
Of course you're going to have to select an appropriate "minimum value" of your selected currency to suit your expected conversions but how is that different from selecting an appropriate epsilon?