Java i18n: Where to get the decimal for the locale

Question: Where do I need to search when I want to know which character will be used for decimal grouping when using this language?

I tried the following code:

Locale locale = new Locale("Finnish", "fi"); DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(locale); System.out.println(format.format(12345678.123)); 

The problem here is that the parameters for the language do not seem to be correct, but I still think that there should be a place where this information can be searched without writing programs for it.

It seems that the material is not taken from the regional settings on my computer, since I changed the characters for the German language in the Windows control panel, but there were no changes in the java program.

+4
source share
2 answers

EDIT: The problem is how you build your Locale . Try simply:

 Locale locale = new Locale("fi"); 

To answer the question of how you get the separator program code, you should use:

 Locale locale = new Locale("fi"); DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(locale); DecimalFormatSymbols symbols = format.getDecimalFormatSymbols(); char groupingChar = symbols.getGroupingSeparator(); 
+11
source

The comment to search the source was too complicated ...

Here where to find the material:

Inside rt.jar jdk in the package sun.text.resources there are files "FormatData_ [ISO-Code] .class" files that contain a symbol for decimal grouping and other related values, and can decompile them. The Java Decompiler ( http://java.decompiler.free.fr ) was very useful for this.

+1
source

All Articles