See: Description
Interface | Description |
---|---|
Money |
This interface represents something generally accepted as a medium of
exchange, a measure of value, or a means of payment.
|
Class | Description |
---|---|
Currency |
This class represents a currency
Unit . |
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 org.jscience.economics.money.Currency.*;
///////////////////////////////////////////////////////////////////////
// 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
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
Like any amount
,
money quantities can be exact or approximate (with an error known
and guaranteed).
[code]
Unit