Setting the Conversion Policy
Whenever your application performs arithmetic operations involving two or more different currencies, one or more currency conversions must take place. A conversion policy determines how the money calculator will express the result of its calculation.
There are four conversion policies available to the money calculator class:
*No Conversion. An operations performed on monies of different currencies throws an exception.
*Base Currency Conversion. When arithmetic operations are performed on monies of different currencies, both operands are converted to a base currency. After performing the calculation, the money calculator returns the result in the base currency.
*Target Currency Conversion. When arithmetic operations are performed on monies of different currencies, the source operand (first argument) is converted to the target operand (second argument) currency. After performing the calculation, the money calculator returns the result in the target currency.
*Source Currency Conversion. When arithmetic operations are performed on monies of different currencies, the target operand (second argument) is converted to the source operand (first argument) currency. After performing the calculation, the money calculator returns the result in the source currency.
A money calculator object’s currency conversion type can be set at construction. It can also be set or changed using the setConversionType() member function.
In addition to setting the conversion type, you must also associate an RWExchangeFactory object with the calculator object. The RWExchangeFactory provides the exchange rate table that is used to perform the conversion. For more information on exchange rates and exchange rate tables, see Exchange Rates and Exchange Rate Tables. The following example shows how you construct an RWMoneyCalculator<T> and some money objects, then perform mixed-currency calculations:
 
typedef RWDecimal< RWMP2Int > Decimal;
RWExchangeRateTable table;
.
.
.
RWExchangeFactory<Decimal> factory( table );
.
.
.
RWMoneyCalculator<Decimal> calculator( factory,
RWMoneyCalculator<Decimal>::target );
 
RWMoney<Decimal> lira(Decimal("12823"), "ITL" );
RWMoney<Decimal> marks(Decimal("1.26"), "DEM" );
 
RWMoney<Decimal> sum = calculator.add( lira, marks );
 
calculator.setConversionType( RWMoneyCalculator<Decimal>::base );
calculator.setBaseCurrency( "USD" );
 
sum = calculator.add( lira, marks );
.
.
.