本文整理汇总了Java中sun.util.resources.LocaleData.getNumberFormatData方法的典型用法代码示例。如果您正苦于以下问题:Java LocaleData.getNumberFormatData方法的具体用法?Java LocaleData.getNumberFormatData怎么用?Java LocaleData.getNumberFormatData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.util.resources.LocaleData
的用法示例。
在下文中一共展示了LocaleData.getNumberFormatData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DecimalFormat
import sun.util.resources.LocaleData; //导入方法依赖的package包/类
/**
* Creates a DecimalFormat using the default pattern and symbols
* for the default locale. This is a convenient way to obtain a
* DecimalFormat when internationalization is not the main concern.
* <p>
* To obtain standard formats for a given locale, use the factory methods
* on NumberFormat such as getNumberInstance. These factories will
* return the most appropriate sub-class of NumberFormat for a given
* locale.
*
* @see java.text.NumberFormat#getInstance
* @see java.text.NumberFormat#getNumberInstance
* @see java.text.NumberFormat#getCurrencyInstance
* @see java.text.NumberFormat#getPercentInstance
*/
public DecimalFormat() {
Locale def = Locale.getDefault();
// try to get the pattern from the cache
String pattern = (String) cachedLocaleData.get(def);
if (pattern == null) { /* cache miss */
// Get the pattern for the default locale.
ResourceBundle rb = LocaleData.getNumberFormatData(def);
String[] all = rb.getStringArray("NumberPatterns");
pattern = all[0];
/* update cache */
cachedLocaleData.put(def, pattern);
}
// Always applyPattern after the symbols are set
this.symbols = new DecimalFormatSymbols(def);
applyPattern(pattern, false);
}
示例2: DecimalFormat
import sun.util.resources.LocaleData; //导入方法依赖的package包/类
/**
* Creates a DecimalFormat using the default pattern and symbols
* for the default locale. This is a convenient way to obtain a
* DecimalFormat when internationalization is not the main concern.
* <p>
* To obtain standard formats for a given locale, use the factory methods
* on NumberFormat such as getNumberInstance. These factories will
* return the most appropriate sub-class of NumberFormat for a given
* locale.
*
* @see java.text.NumberFormat#getInstance
* @see java.text.NumberFormat#getNumberInstance
* @see java.text.NumberFormat#getCurrencyInstance
* @see java.text.NumberFormat#getPercentInstance
*/
public DecimalFormat() {
Locale def = Locale.getDefault(Locale.Category.FORMAT);
// try to get the pattern from the cache
String pattern = cachedLocaleData.get(def);
if (pattern == null) { /* cache miss */
// Get the pattern for the default locale.
ResourceBundle rb = LocaleData.getNumberFormatData(def);
String[] all = rb.getStringArray("NumberPatterns");
pattern = all[0];
/* update cache */
cachedLocaleData.putIfAbsent(def, pattern);
}
// Always applyPattern after the symbols are set
this.symbols = new DecimalFormatSymbols(def);
applyPattern(pattern, false);
}
示例3: getInstance
import sun.util.resources.LocaleData; //导入方法依赖的package包/类
private static NumberFormat getInstance(Locale desiredLocale,
int choice) {
// Check whether a provider can provide an implementation that's closer
// to the requested locale than what the Java runtime itself can provide.
LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(NumberFormatProvider.class);
if (pool.hasProviders()) {
NumberFormat providersInstance = pool.getLocalizedObject(
NumberFormatGetter.INSTANCE,
desiredLocale,
choice);
if (providersInstance != null) {
return providersInstance;
}
}
/* try the cache first */
String[] numberPatterns = (String[])cachedLocaleData.get(desiredLocale);
if (numberPatterns == null) { /* cache miss */
ResourceBundle resource = LocaleData.getNumberFormatData(desiredLocale);
numberPatterns = resource.getStringArray("NumberPatterns");
/* update cache */
cachedLocaleData.put(desiredLocale, numberPatterns);
}
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(desiredLocale);
int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);
if (choice == INTEGERSTYLE) {
format.setMaximumFractionDigits(0);
format.setDecimalSeparatorAlwaysShown(false);
format.setParseIntegerOnly(true);
} else if (choice == CURRENCYSTYLE) {
format.adjustForCurrencyDefaultFractionDigits();
}
return format;
}
示例4: getInstance
import sun.util.resources.LocaleData; //导入方法依赖的package包/类
private static NumberFormat getInstance(Locale desiredLocale,
int choice) {
// Check whether a provider can provide an implementation that's closer
// to the requested locale than what the Java runtime itself can provide.
LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(NumberFormatProvider.class);
if (pool.hasProviders()) {
NumberFormat providersInstance = pool.getLocalizedObject(
NumberFormatGetter.INSTANCE,
desiredLocale,
choice);
if (providersInstance != null) {
return providersInstance;
}
}
/* try the cache first */
String[] numberPatterns = (String[])cachedLocaleData.get(desiredLocale);
if (numberPatterns == null) { /* cache miss */
ResourceBundle resource = LocaleData.getNumberFormatData(desiredLocale);
numberPatterns = resource.getStringArray("NumberPatterns");
/* update cache */
cachedLocaleData.put(desiredLocale, numberPatterns);
}
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(desiredLocale);
int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);
if (choice == INTEGERSTYLE) {
format.setMaximumFractionDigits(0);
format.setDecimalSeparatorAlwaysShown(false);
format.setParseIntegerOnly(true);
} else if (choice == CURRENCYSTYLE) {
format.adjustForCurrencyDefaultFractionDigits();
}
return format;
}
示例5: getDefaultPattern
import sun.util.resources.LocaleData; //导入方法依赖的package包/类
private static String getDefaultPattern(Locale locale) {
// Get the pattern for the default locale.
ResourceBundle rb = LocaleData.getNumberFormatData(locale);
String[] all = rb.getStringArray("NumberPatterns");
return all[0];
}