Taken directly from the manual.
Local sensitive formatting
In the previous example, a DecimalFormat object was created for the default locale. If you need a DecimalFormat object for an unlimited locale, you create an instance of NumberFormat and then pass it to DecimalFormat. Here is an example:
NumberFormat nf = NumberFormat.getNumberInstance(loc); DecimalFormat df = (DecimalFormat)nf; df.applyPattern(pattern); String output = df.format(value); System.out.println(pattern + " " + output + " " + loc.toString());
Execution of the previous code example leads to the following result. The formatted number, which is in the second column, depends on the language:
., 123.456,789 de_DE .
source share