November 2006
Intermediate to advanced
224 pages
3h 29m
English
double currency = 567123678.99; NumberFormat currencyFormatter; String formattedCurrency; currencyFormatter = NumberFormat.getCurrencyInstance(); formattedCurrency = currencyFormatter.format(currency); System.out.format("%s%n", formattedCurrency); |
As with the previous phrase on formatting numbers, here we make use of the NumberFormat class, but this time to format a currency value. We use the getCurrencyInstance() of the NumberFormat class to get a currency formatting instance of the class. Using this instance, we can pass a floating point value and it will return a formatted currency value. The output of the phrase shown will be the following string:
$567,123,678.99
In addition to placing commas in the appropriate places, ...
Read now
Unlock full access