嗨,我正在努力格式化数字,如 NumberFormat.getInstance() 的文档所述。 (Windows 7、NetBeans、Java 7)
我首先进入区域设置并删除了英语、英语键盘和所有内容。我把它全部设置为法语和法国。我什至重新启动了我的电脑。我的代码是:
System.setProperty("user.language", "fr");
System.setProperty("user.country", "FR");
System.setProperty("user.language.display", "fr");
System.setProperty("user.country.display", "FR");
System.setProperty("user.language.format", "fr");
System.setProperty("user.country.format", "FR");
Locale locale = new Locale("French", "France");
Locale.setDefault(locale);
Locale.setDefault(Locale.Category.DISPLAY, locale);
Locale.setDefault(Locale.Category.FORMAT, locale);
java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
System.out.println(nf.format(4.5));
尽管如此,程序还是打印了“4.5”。我不明白,对于法国法国来说,这应该是“4,5”。我还需要做什么?
最佳答案
这就是问题:
Locale locale = new Locale("French", "France");
应该是:
Locale locale = new Locale("fr", "FR");
或者只使用Locale.FRENCH
。
此外,您无需设置任何属性或更改默认区域设置。只需获取您感兴趣的区域设置的 NumberFormat
即可。
关于java - 默认区域设置和数字格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14678558/