![]() |
The Java Developers Almanac 1.4 |
|
e314. Formatting and Parsing Locale-Specific Currency // Format
Locale locale = Locale.GERMANY;
String string = NumberFormat.getCurrencyInstance(locale).format(123.45);
// 123,45 DM
locale = Locale.CANADA;
string = NumberFormat.getCurrencyInstance(locale).format(123.45);
// $123.45
// Parse
try {
Number number = NumberFormat.getCurrencyInstance(locale).parse("$123.45");
// 123.45
if (number instanceof Long) {
// Long value
} else {
// Double value
}
} catch (ParseException e) {
}
e312. Formatting and Parsing a Number for a Locale e313. Formatting a Number in Exponential Notation e315. Formatting and Parsing a Locale-Specific Percentage
© 2002 Addison-Wesley. |