RWMoney<T> provides global operators for performing same-currency arithmetic calculations in C++, and Money provides a similar set of arithmetic methods in Java. When objects created from these classes are used in arithmetic operations, all operands must be the same currency. If the currencies for operands in the same equation differ, the operator throws an exception (or, in Java, the method calls the error handler).
Similarly, all assignments to money objects must have the same currency as the original object. If not, an exception is thrown.
Here are some examples:
Example 1, C++:
. . . 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. . . .
Example 2, Java:
s = x.plus(y) // Okay, same currencies s = y.minus(z); // Error, currencies differ. Exception thrown.
©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.