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


Java DecimalFormat.applyLocalizedPattern方法代碼示例

本文整理匯總了Java中java.text.DecimalFormat.applyLocalizedPattern方法的典型用法代碼示例。如果您正苦於以下問題:Java DecimalFormat.applyLocalizedPattern方法的具體用法?Java DecimalFormat.applyLocalizedPattern怎麽用?Java DecimalFormat.applyLocalizedPattern使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.text.DecimalFormat的用法示例。


在下文中一共展示了DecimalFormat.applyLocalizedPattern方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getDecimalFormat

import java.text.DecimalFormat; //導入方法依賴的package包/類
/**
 * Make an instance of DecimalFormat.
 *
 * @param locale The locale
 * @param pattern The pattern is used for the convertion
 * @return The format for the locale and pattern
 *
 * @throws ConversionException if conversion cannot be performed
 *  successfully
 * @throws ParseException if an error occurs parsing a String to a Number
 */
private DecimalFormat getDecimalFormat(final Locale locale, final String pattern) {

    final DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance(locale);

    // if some constructors default pattern to null, it makes only sense to handle null pattern gracefully
    if (pattern != null) {
        if (locPattern) {
            numberFormat.applyLocalizedPattern(pattern);
        } else {
            numberFormat.applyPattern(pattern);
        }
    } else {
        log.debug("No pattern provided, using default.");
    }

    return numberFormat;
}
 
開發者ID:yippeesoft,項目名稱:NotifyTools,代碼行數:29,代碼來源:StringLocaleConverter.java

示例2: formatNumber

import java.text.DecimalFormat; //導入方法依賴的package包/類
public static String formatNumber(double number, String pattern,
                                  DecimalFormat formatter) {
    // bugzilla fix 12813
    if (formatter == null) {
        formatter = defaultFormatter;
    }
    try {
        StringBuffer result = threadLocalStringBuffer.get();
    result.setLength(0);
        if (pattern != defaultPattern) {
            formatter.applyLocalizedPattern(pattern);
        }
    formatter.format(number, result, _fieldPosition);
        return result.toString();
    }
    catch (IllegalArgumentException e) {
        runTimeError(FORMAT_NUMBER_ERR, Double.toString(number), pattern);
        return(EMPTYSTRING);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:BasisLibrary.java

示例3: parse

import java.text.DecimalFormat; //導入方法依賴的package包/類
/**
 * Convert the specified locale-sensitive input object into an output
 * object of the specified type.
 *
 * @param value The input object to be converted
 * @param pattern The pattern is used for the convertion
 * @return The converted value
 *
 * @throws org.apache.commons.beanutils.ConversionException if conversion
 * cannot be performed successfully
 * @throws ParseException if an error occurs parsing a String to a Number
 */
@Override
protected Object parse(final Object value, final String pattern) throws ParseException {

    if (value instanceof Number) {
        return value;
    }

    // Note that despite the ambiguous "getInstance" name, and despite the
    // fact that objects returned from this method have the same toString
    // representation, each call to getInstance actually returns a new
    // object.
    final DecimalFormat formatter = (DecimalFormat) DecimalFormat.getInstance(locale);

    // if some constructors default pattern to null, it makes only sense
    // to handle null pattern gracefully
    if (pattern != null) {
        if (locPattern) {
            formatter.applyLocalizedPattern(pattern);
        } else {
            formatter.applyPattern(pattern);
        }
    } else {
        log.debug("No pattern provided, using default.");
    }

    return formatter.parse((String) value);
}
 
開發者ID:yippeesoft,項目名稱:NotifyTools,代碼行數:40,代碼來源:DecimalLocaleConverter.java


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