#include <rw/money/money.h> RWMoney<double> m(1.25, "CAD");
com.roguewave.money.currency.v1_0.Money
Class RWMoney<T> provides a mapping between an amount and a currency, by encapsulating a decimal value and referencing a currency. The C++ and Java versions of this class differ. In C++, the value is an arbitrary decimal type specified as a template parameter. In Java, the value is either a double or a BigDecimal.
When RWMoney objects are used in arithmetic operations, all operands must be the same currency. If the currencies for RWMoney operands used in the same equation differ, the operator (or method, in Java) will throw an exception. Similarly, all assignments to RWMoney objects must have the same currency as the original object. If not, an exception is thrown.
Operations between monies of different currencies may be performed using class RWMoneyCalculator<T>.
Here is an example assignment and some arithmetic calculations:
Example
. . . RWMoney<RWDecimal64> x("1.23","USD"), y("9.87","USD"), z("7.99","CAD"); RWMoney<RWDecimal64> s("0","USD"); s = x + y; // Okay, same currencies s = y - z; // Error, different currencies. Exception thrown. s = x; // Okay, same currencies s = z; // Error, different currencies. Exception thrown. . . .
RWMoney();
Default constructor. Behavior is undefined.
RWMoney(const RWMoney<T>& m);
Copy constructor.
RWMoney(const T& amount, const RWCString currencyMnemonic);
Constructs a money object with the given amount and currency.
RWMoney(const RWCString currencyMnemonic);
Constructs a money object with the given currency and amount equal to zero.
RWMoney<T>& operator=(const RWMoney<T>& rhs);
Sets contents of self to rhs.
RWMoney<T>& operator+=(const RWMoney<T>& rhs);
Sets contents of self to self plus rhs.
RWMoney<T>& operator-=(const RWMoney<T>& rhs);
Sets contents of self to self minus rhs.
RWMoney<T>& operator*=(const T& rhs);
Sets contents of self to self times rhs.
RWMoney<T>& operator/=(const T& rhs);
Sets contents of self to self divided by rhs.
RWMoney<T> operator-();
Returns negation of self. Returned money object will have the same currency as self, but amount will be the negative of self.
T amount() const;
Returns the amount.
RWCString currency() const;
Returns the currency's mnemonic
void restoreFrom(RWFile&);
Restore from an RWFile.
void restoreFrom(RWvistream&);
Restore from a virtual stream.
void saveOn(RWFile&) const;
Persist to an RWFile.
void saveOn(RWvostream&) const;
Persist to a virtual stream.
void setAmount(const T& amt);
Sets the amount.
void setCurrency(const RWCString& currencyMnemonic);
Sets the currency mnemonic
RWMoney<T> operator+(const RWMoney<T>& lhs, const RWMoney<T>& rhs);
Addition operator.
RWMoney<T> operator-(const RWMoney<T>& lhs, const RWMoney<T>& rhs);
Subtraction operator.
RWMoney<T> operator*(const RWMoney<T>& lhs, const T& rhs); RWMoney<T> operator*(const T& lhs, const RWMoney<T>& rhs);
Multiplication operators.
RWMoney<T> operator/(const RWMoney<T>& lhs, const T& rhs);
Division operator.
RWBoolean operator<(const RWMoney<T>& lhs, const RWMoney<T>& rhs); RWBoolean operator<=(const RWMoney<T>& lhs, const RWMoney<T>& rhs); RWBoolean operator>(const RWMoney<T>& lhs, const RWMoney<T>& rhs); RWBoolean operator>=(const RWMoney<T>& lhs, const RWMoney<T>& rhs); RWBoolean operator==(const RWMoney<T>& lhs, const RWMoney<T>& rhs); RWBoolean operator!=(const RWMoney<T>& lhs, const RWMoney<T>& rhs);
Logical operators.
RWvostream& operator<<(RWvostream& strm, const RWMoney<T>& c); RWFile& operator<<(RWFile& file, const RWMoney<T>& c);
Saves the object to a virtual stream or RWFile, respectively.
RWvistream& operator>>(RWvistream& strm, const RWMoney<T>& c); RWFile& operator>>(RWFile& strm, const RWMoney<T>& c);
Restores a object from a virtual stream or RWFile, respectively.
RWMoney<T> round(const RWMoney<T>& m, unsigned int places);
Rounds the amount to the indicated number of decimal places. See the description of class RWMoneyCalculator for a discussion of the available rounding methods.
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.