|
JADE v6.1 | |||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
See:
Description
Class Summary | |
Currency | This class represents a currency Unit . |
Money | This class represents something generally accepted as a medium of exchange, a measure of value, or a means of payment. |
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:
/////////////////////////////////////////////////////////////////////// // Calculates the cost of a car trip in Europe for an American tourist. /////////////////////////////////////////////////////////////////////// // Use currency symbols instead of ISO-4217 codes. UnitFormat.label(Currency.USD, "$"); // Use "$" symbol instead of currency code ("USD") UnitFormat.label(Currency.EUR, "€"); // Use "€" symbol instead of currency code ("EUR") // Calculates trip cost. Quantity carMileage = Quantity.valueOf(20, NonSI.MILE.divide(NonSI.GALLON_LIQUID_US)); // 20 mi/gal. Quantity gazPrice = Quantity.valueOf(1.2, Currency.EUR.divide(NonSI.LITER)); // 1.2 €/L Length tripDistance = (Length) Quantity.valueOf(400, SI.KILO(SI.METER)); // 400 km Money tripCost = (Money) tripDistance.divide(carMileage).multiply(gazPrice); // Sets exchange rates. Currency.setReferenceCurrency(Currency.USD); Currency.EUR.setExchangeRate(1.17); // 1.0 € = 1.17 $ // Displays cost. Money.showAs(Currency.USD); System.out.println("Trip cost = " + tripCost + " (" + tripCost.toString(Currency.EUR) + ")"); > Trip cost = 66.05 $ (56.45 €)
|
JADE v6.1 | |||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |