如何获取特定区域设置的数字格式模式? [英] How to get the pattern of Number Format of a specific locale?
问题描述
我有一个简单的问题:
如何使用 NumberFormat
创建用于格式化数字的模式对于特定的语言环境,如下所示:
How to get the pattern used to format a number using NumberFormat
created for a specific locale as shown below:
import java.util.Locale;
Locale aLocale = new Locale("fr","CA");
NumberFormat numberFormat=NumberFormat.getNumberInstance(aLocale);
这里我想知道用于格式化法语<中的数字的模式/ code>语言和国家
加拿大
。
Here I want to know the pattern used to format a number in French
language and the country of Canada
.
例如:
数字 123456.7890
转换为 123 456,789
格式化后,表示模式可能是 ####,###
,用于上述语言环境。
a number 123456.7890
is converted into 123 456,789
after formatting it means pattern may be # ###,###
for above mentioned locale.
推荐答案
子类DecimalFormat和ChoiceFormat有一个方法toPattern(),所以你必须检查使用instanceof并调用toPattern()
The subclasses DecimalFormat and ChoiceFormat have a method toPattern(), so you must check using instanceof and call toPattern()
String pattern = null;
if (numberFormat instanceof DecimalFormat) {
pattern = ((DecimalFormat)numberFormat).toPattern();
}
考虑DecimalFormat.toLocalizedPattern()
Consider DecimalFormat.toLocalizedPattern() too
这篇关于如何获取特定区域设置的数字格式模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!