本文整理汇总了Java中java.text.NumberFormat.getAvailableLocales方法的典型用法代码示例。如果您正苦于以下问题:Java NumberFormat.getAvailableLocales方法的具体用法?Java NumberFormat.getAvailableLocales怎么用?Java NumberFormat.getAvailableLocales使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.NumberFormat
的用法示例。
在下文中一共展示了NumberFormat.getAvailableLocales方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Test4106136
import java.text.NumberFormat; //导入方法依赖的package包/类
public void Test4106136() {
Locale saveLocale = Locale.getDefault();
try {
Locale[] locales = {Locale.CHINESE, Locale.CHINA};
for (int i = 0; i < locales.length; ++i) {
Locale.setDefault(locales[i]);
int[] n = {
getAvailableLocales().length,
DateFormat.getAvailableLocales().length,
NumberFormat.getAvailableLocales().length};
for (int j = 0; j < n.length; ++j) {
if (n[j] == 0) {
errln("Fail: No locales for " + locales[i]);
}
}
}
} finally {
Locale.setDefault(saveLocale);
}
}
示例2: TestEuroSupport
import java.text.NumberFormat; //导入方法依赖的package包/类
/**
* @bug 4122371
* Confirm that Euro support works. This test is pretty rudimentary; all it does
* is check that any locales with the EURO variant format a number using the
* Euro currency symbol.
*
* ASSUME: All locales encode the Euro character "\u20AC".
* If this is changed to use the single-character Euro symbol, this
* test must be updated.
*
* DON'T ASSUME: Any specific countries support the Euro. Instead,
* iterate through all locales.
*/
public void TestEuroSupport() {
final String EURO_VARIANT = "EURO";
final String EURO_CURRENCY = "\u20AC"; // Look for this string in formatted Euro currency
Locale[] locales = NumberFormat.getAvailableLocales();
for (int i = 0; i < locales.length; ++i) {
Locale loc = locales[i];
if (loc.getVariant().indexOf(EURO_VARIANT) >= 0) {
NumberFormat nf = NumberFormat.getCurrencyInstance(loc);
String pos = nf.format(271828.182845);
String neg = nf.format(-271828.182845);
if (pos.indexOf(EURO_CURRENCY) >= 0
&& neg.indexOf(EURO_CURRENCY) >= 0) {
logln("Ok: " + loc.toString()
+ ": " + pos + " / " + neg);
} else {
errln("Fail: " + loc.toString()
+ " formats without " + EURO_CURRENCY
+ ": " + pos + " / " + neg
+ "\n*** THIS FAILURE MAY ONLY MEAN THAT LOCALE DATA HAS CHANGED ***");
}
}
}
}
示例3: getAvailableLocales
import java.text.NumberFormat; //导入方法依赖的package包/类
/**
* Return an array of all locales for which the getInstance() method of this class can
* return localized instances. See {@link java.text.NumberFormat#getAvailableLocales()}
*/
public static Locale[] getAvailableLocales() { return NumberFormat.getAvailableLocales(); }