Performs algebraic operations when the money operands in an equation are not of the same currency.
More...
|
| RWMoneyCalculator () |
|
| RWMoneyCalculator (const RWExchangeFactory< T > &ef, ConversionType ct, const RWCString &baseCurr="", RoundMethod rm=noRounding, unsigned int accuracy=2, unsigned int roundDigit=5) |
|
| RWMoneyCalculator (const RWExchangeRateTable &ert, ConversionType ct, const RWCString &baseCurr="", RoundMethod rm=noRounding, unsigned int accuracy=2, unsigned int roundDigit=5) |
|
| RWMoneyCalculator (const RWMoneyCalculator< T > &calc) |
|
| RWMoneyCalculator (RoundMethod rm, unsigned int accuracy, unsigned int roundDigit=5) |
|
RWMoney< T > | abs (const RWMoney< T > &x) const |
|
unsigned int | accuracy () const |
|
RWMoney< T > | add (const RWMoney< T > &lhs, const RWMoney< T > &rhs) const |
|
RWCString | baseCurrency () const |
|
ConversionType | conversionType () const |
|
RWMoney< T > | divide (const RWMoney< T > &lhs, const T &rhs) const |
|
bool | equal (const RWMoney< T > &lhs, const RWMoney< T > &rhs) const |
|
RWExchangeFactory< T > & | exchangeFactory () |
|
RWExchangeFactory< T > | exchangeFactory () const |
|
bool | greaterThan (const RWMoney< T > &lhs, const RWMoney< T > &rhs) const |
|
bool | greaterThanOrEqual (const RWMoney< T > &lhs, const RWMoney< T > &rhs) const |
|
bool | greaterThanZero (const RWMoney< T > &x) const |
|
bool | isZero (const RWMoney< T > &x) const |
|
bool | lessThan (const RWMoney< T > &lhs, const RWMoney< T > &rhs) const |
|
bool | lessThanOrEqual (const RWMoney< T > &lhs, const RWMoney< T > &rhs) const |
|
bool | lessThanZero (const RWMoney< T > &x) const |
|
RWMoney< T > | multiply (const RWMoney< T > &lhs, const T &rhs) const |
|
RWMoney< T > | multiply (const T &lhs, const RWMoney< T > &rhs) const |
|
RWMoneyCalculator< T > & | operator= (const RWMoneyCalculator< T > &) |
|
RWMoney< T > | round (const RWMoney< T > &) const |
|
unsigned int | roundDigit () const |
|
RoundMethod | roundMethod () const |
|
bool | sameCurrency (const RWMoney< T > &lhs, const RWMoney< T > &rhs) const |
|
void | setAccuracy (unsigned int a) |
|
void | setConversionType (ConversionType ct) |
|
void | setExchangeFactory (const RWExchangeFactory< T > &f) |
|
void | setRoundDigit (unsigned int rd) |
|
void | setRoundMethod (RoundMethod rm) |
|
RWMoney< T > | subtract (const RWMoney< T > &lhs, const RWMoney< T > &rhs) const |
|
template<class T>
class RWMoneyCalculator< T >
Class RWMoneyCalculator can perform algebraic operations when the money operands in the equation are not of the same currency. Because some conversion from one currency to another must occur before such an operation can be carried out, RWMoneyCalculator lets you specify a conversion policy for calculator objects.
- Synopsis
#include <rw/currency/moneycalc.h>
Performs algebraic operations when the money operands in an equation are not of the same currency.
Definition moneycalc.h:101
Conversion Policies
Four conversion policies are available:
- No Conversion. Any operations performed on monies of different currencies will throw an exception.
- Base Currency Conversion. When arithmetic operations are performed on monies of different currencies both operands will first be converted to the base currency. The operation will then be performed and the result returned 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 and the result is returned 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 and the result is returned in the source currency.
Conversions are carried out through the RWExchangeFactory object that is associated with the particular calculator object.
Rounding Policies
In addition to setting the conversion policy, you must set a rounding policy and an accuracy for the calculator. The accuracy specifies how many digits to the right of the decimal points should be reported. Rounding a negative number is equivalent to rounding the absolute value of the negative number, then multiplying the result by negative one. Briefly, the available rounding policies available for RWMoneyCalculator are:
- Don't round. No rounding will occur, and accuracy is ignored.
- Round up. Always add one to the digit at the specified accuracy decimal place, then truncate any digits to the right.
- Round down. Truncate all digits to the right of the specified accuracy decimal place.
- Plain. If the digit one to the right of the specified accuracy decimal place is greater than a comparison digit, increase the digit at the accuracy position by one and truncate all numbers to the right. Otherwise, truncate all digits to the right of the accuracy place digit.
- Bankers. If the digit one to the right of the specified accuracy decimal place is equal to a comparison digit, round so that the digit at the specified accuracy position is even. If the digit one to the right of the specified accuracy position is greater than a comparison digit, increment by one the digit at the specified accuracy position. If the digit one to the right of the specified accuracy position is less than a comparison digit, truncate all numbers to the right of the accuracy position.