
Java also uses picture strings to format numbers, however, those picture strings differ from the strings in the Money.h++ C++ library. For a complete description, see the API documentation for class java.text.DecimalFormat.
Here is some example code that shows a currency exchange operation, followed by a formatting operation:
// an amount in US$
Money USDbucks = new Money("232.455", "USD");
// today's exchange rate
ExchangeRate rate = new ExchangeRate("USD", "CAD", 1.5536);
MultiplicationExchange USDtoCAD = new MultiplicationExchange(rate);
Money CADbucks =
USDtoCAD.exchange(USDbucks).round(2, Money.ROUND_BANKERS, 5);
// set up the US dollars format.
MoneyFormat USDformat = new MoneyFormat("USD$##########.##");
// the Canadian dollars format is the same as the US, except for
// the currency symbol
MoneyFormat CADformat = new MoneyFormat("CAD$##########.##");
System.out.println("Initial amount is " +
USDformat.format(USDbucks));
System.out.println("After exchange it is " +
CADformat.format(CADbucks));
©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.