views:

180

answers:

2

Question: Where do I have to look when I want to know which character will be used for decimal grouping when using a given locale?

I tried the following code:

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

Problem here is, that the parameters for the locale don't seem to be correct but I anyway think there must be some place where this information can be looked up without writing programs for it.

It seems the stuff is not taken from the regional settings on my machine as I changed the characters for the german language in the windows control panel but there was no change within the java program.

+5  A: 

EDIT: The problem is the way you're constructing your Locale. Try just:

Locale locale = new Locale("fi");

To answer the question about how you'd get the separator programmatically, you'd use:

Locale locale = new Locale("fi");
DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(locale);
DecimalFormatSymbols symbols = format.getDecimalFormatSymbols();
char groupingChar = symbols.getGroupingSeparator();
Jon Skeet
Thanks for the hint about the locale object!The thing about the grouping separator is that I am curious where this information is retrieved from. There must be some kind of file where it is stored.
Mathias Weyel
I suggest you have a look at the source code - it's very handy that it's all available for inspection :)
Jon Skeet
A: 

The comment for looking in the source had been too challenging...

Here's where the stuff is to be found:

Within the rt.jar of the jdk, in the package sun.text.resources there are files "FormatData_[ISO-Code].class" files in which the character for decimal grouping and the other related values are contained and can be viewed by decompiling them. The Java Decompiler (http://java.decompiler.free.fr) has been very helpful on that one.

Mathias Weyel