
On Mon, Jun 20, 2005 at 11:12:22PM +0000, Martin wrote:
The current library got basic_money and basic_currency classes based on a money_traits class which handles the adaptation for the underlying arithmetic class.
Does the traits class handle rounding?
template <typename ArithmeticT, typename TraitsT = money_traits<ArithmeticT> > class basic_money;
In my attempt at a money class, I have one extra template parameter, which represents the number of digits past the decimal point. I figured this is fundamental enough to be included in the type.
template <typename MoneyT, typename CurrencyT = currency_type> class basic_currency;
typedef basic_money<decimalF64> mymoney; mymoney m(5.25, decimals(2), round_to_nearest);
const currency_type EUR("EUR"), USD("USD"); typedef basic_currency<basic_money<decimal64> > mycurrency; mycurrency c(1.23, digits(3), EUR), d(1.23, "USD");
Nice. This seems similar in direction to Daniel Frey's money classes, which has the weight of actual company usage behind it. The only drawback is that the currency units is not part of the currency type, but rather something checked at runtime via exceptions. What is the rationale behind that? From the outside, it looks safer to catch this at compile time, but I suppose usage of these classes is easier if it is a value? I'd like to be convinced your method is the best. Is the latest code available somewhere? Thanks, - Chris