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.
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();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With