當前位置: 首頁>>代碼示例>>Java>>正文


Java NumberFormat.getAvailableLocales方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:CalendarRegression.java

示例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 ***");
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:38,代碼來源:LocaleTest.java

示例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(); }
 
開發者ID:creativechain,項目名稱:creacoinj,代碼行數:6,代碼來源:BtcFormat.java


注:本文中的java.text.NumberFormat.getAvailableLocales方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。