开发者

Java i18n: Where to get the decimal grouping character for a locale

开发者 https://www.devze.com 2022-12-17 07:30 出处:网络
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?

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));

Pro开发者_Python百科blem 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消