Provides support for monetary quantities and their currencies.


Interface Summary
ChangeSource A class representing a currency conveter.
Money This interface represents something generally accepted as a medium of exchange, a measure of value, or a means of payment.
QuoteSource Interface for classes that will retrieve quotes from data sources.
SymbolSource Interface for classes that perform symbol searches.

Class Summary
Account A class representing a bank account on which you can store money or properties on some things.
Check A class representing a paper form of payment from one person to another.
Coin A class representing a metal or paper form of payment from one person to another.
Currencies A class representing a list of common currencies as of circa 2000.
Currency This class represents a currency Unit.
MoneyUtils A class prividing useful methods to compute interest rates...
Quote A class representing a Quote on a market.
Receipt A class representing a receipt for the person who pays or a bill for the person who provides the goods or services.
Share A class representing a share in a company, a value, a title of ownership.
Transaction A class representing an exchange of money and goods or services between two parties.
Wallet A class representing a wallet (a store of money).

Package Description

Provides support for monetary quantities and their currencies.

Conversions between quantities stated in different currencies is possible if the exchange rates for the currencies have been set (otherwise ConversionException is thrown).

Monetary quantities support the dynamic changes of the currencies exchange rates as illustrated in the following example:[code] import static javax.measure.units.SI.*; import static javax.measure.units.NonSI.*; import static*; /////////////////////////////////////////////////////////////////////// // Calculates the cost of a car trip in Europe for an American tourist. /////////////////////////////////////////////////////////////////////// // Use currency symbols instead of ISO-4217 codes. UnitFormat.getStandardInstance().label(USD, "$"); // Use "$" symbol instead of currency code ("USD") UnitFormat.getStandardInstance().label(EUR, "€"); // Use "€" symbol instead of currency code ("EUR") // Sets exchange rates. Currency.setReferenceCurrency(USD); EUR.setExchangeRate(1.17); // 1.0 € = 1.17 $ // Calculates trip cost. Amount carMileage = Amount.valueOf(20, MILE.divide(GALLON_LIQUID_US)); // 20 mi/gal. Amount gazPrice = Amount.valueOf(1.2, EUR.divide(LITER)); // 1.2 €/L Amount tripDistance = Amount.valueOf(400, KILO(METRE)); // 400 km Amount tripCost = tripDistance.divide(carMileage).times(gazPrice).to(USD); // Displays cost. System.out.println("Trip cost = " + tripCost + " (" + + ")"); > Trip cost = 66.05 $ (56.45 €) [/code]

The exchange rates between currencies is context local. Application may use different sets of exchange rates concurrently (e.g. rates for buying and rates for selling). For example:[code] LocalContext.enter(); try { EUR.setExchangeRate(1.22); // Buying rate. Amount price = Amount.valueOf(9.99, EUR); System.out.println("Price: " +; } finally { LocalContext.exit(); } ... LocalContext.enter(); try { EUR.setExchangeRate(1.18); // Selling rate. Amount price = Amount.valueOf(14.99, USD); System.out.println("Price: " +; } finally { LocalContext.exit(); }[/code]

Like any amount, money quantities can be exact or approximate (with an error known and guaranteed). [code] Unit CENTS = Currency.USD.times(100); Amount exactPrice = Amount.valueOf(1499, CENTS); // Integer value. Amount apprxPrice = Amount.valueOf(14.99, USD); // Floating-Point IEEE 754 accuracy. [/code]