本文整理汇总了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;
}
示例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);
}
}
示例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);
}