| NumberFormat has features designed to make it possible to
format numbers in any locale. It also supports different kinds of numbers,
including integers (123), fixed-point numbers (123.4), percentages (12%),
and currency amounts ($123). All of these can be localized.
To obtain a NumberFormat for a specific locale call one of
NumberFormat 's factory methods, such as:
-
getPercentageInstance(locale)
-
getIntegerInstance(locale)
-
getCurrencyInstance(locale)
-
getDecimalInstance(local)
Usage:
NumberFormat f = NumberFormat.getCurrencyInstance(loc);
StringBuffer sb = f.format(new Double(123.45), new StringBuffer());
Or eventualy it's possible to change number of decimals displayed
NumberFormat f = NumberFormat.getCurrencyInstance(loc);
f.setMaximumFractionDigits(2);
StringBuffer sb = f.format(new Double(123.45559), new StringBuffer());
|