Hi I am struggling to format numbers like the documentation for NumberFormat.getInstance() says.
(Windows 7, NetBeans, Java 7)
I have first gone into regional settings and removed us english, us english keyboards and everything. I set it all to French and France. I even rebooted my pc. My code is:
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));
Despite all of this, the program prints “4.5”. I don’t understand, for French France this should be “4,5”. What more do I need to do?
This is the problem:
It should be:
Or just use
Locale.FRENCH.Additionally, you don’t need to set any properties or change the default locale. Just fetch the
NumberFormatfor the locale you’re interested in.