当前位置: 首页>>代码示例>>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;未经允许,请勿转载。