代码:
Locale locale=new java.util.Locale("nb");// locale for Norwegian, Bokmal (Norway)
DecimalFormat decimalFormatter=(DecimalFormat) DecimalFormat.getInstance(locale);
System.out.println(decimalFormatter.toLocalizedPattern());
System.out.println(locale.getDisplayLanguage());
System.out.println(decimalFormatter.format(1234.567));
输出:
# ##0,###
Norwegian Bokmål
1 234,567
#,##0.###
Norwegian Bokmål
1,234.567
Java Version : JDK.1.6.0_23
Web Server : Jetty enclosed in Eclipse Juno
修改
以下是@haraldK
建议的一些调查结果以下是内部调用私有方法NumberFormat.getInstance(Locale)的NumberFormat.getInstance(Locale,int)源代码,如下所示:
private static NumberFormat getInstance(Locale desiredLocale,
int choice) {
// Check whether a provider can provide an implementation that's closer
// to the requested locale than what the Java runtime itself can provide.
LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(NumberFormatProvider.class);
if (pool.hasProviders()) {
NumberFormat providersInstance = pool.getLocalizedObject(
NumberFormatGetter.INSTANCE,
desiredLocale,
choice);
if (providersInstance != null) {
return providersInstance;
}
}
...
}