本文整理汇总了Java中java.text.DecimalFormat.setParseBigDecimal方法的典型用法代码示例。如果您正苦于以下问题:Java DecimalFormat.setParseBigDecimal方法的具体用法?Java DecimalFormat.setParseBigDecimal怎么用?Java DecimalFormat.setParseBigDecimal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.DecimalFormat
的用法示例。
在下文中一共展示了DecimalFormat.setParseBigDecimal方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import java.text.DecimalFormat; //导入方法依赖的package包/类
private void build() {
try {
if (typeQualifier != null) {
buildQualifiedNumber();
return;
}
Number value;
if (number.contains(".")) {
DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
decimalFormat.setParseBigDecimal(true);
int decSymbolIndex = number.lastIndexOf(".");
if (decSymbolIndex > -1) {
int precision = number.substring(decSymbolIndex, number.length() - 1).length();
decimalFormat.setMaximumFractionDigits(precision);
}
value = decimalFormat.parse(number);
} else {
value = NumberFormat.getInstance(locale).parse(number);
}
set(value);
} catch (ParseException e) {
throw new RuntimeException(String.format("Invalid number '%s'", number));
}
}
示例2: convertToBigDecimal
import java.text.DecimalFormat; //导入方法依赖的package包/类
private static BigDecimal convertToBigDecimal(Object o) {
DecimalFormat df = new DecimalFormat();
df.setParseBigDecimal(true);
try {
return (BigDecimal) df.parse(o.toString());
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例3: getNumberFormat
import java.text.DecimalFormat; //导入方法依赖的package包/类
@Override
public NumberFormat getNumberFormat(Locale locale) {
NumberFormat format = NumberFormat.getInstance(locale);
if (!(format instanceof DecimalFormat)) {
if (this.pattern != null) {
throw new IllegalStateException("Cannot support pattern for non-DecimalFormat: " + format);
}
return format;
}
DecimalFormat decimalFormat = (DecimalFormat) format;
decimalFormat.setParseBigDecimal(true);
if (this.pattern != null) {
decimalFormat.applyPattern(this.pattern);
}
return decimalFormat;
}
示例4: parse
import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
* Regardless of the default locale, comma ('.') is used as decimal separator
*
* @param source
* @return
* @throws ParseException
*/
public BigDecimal parse(String source) throws ParseException {
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
DecimalFormat format = new DecimalFormat("#.#", symbols);
format.setParseBigDecimal(true);
return (BigDecimal) format.parse(source);
}
示例5: getFormat
import java.text.DecimalFormat; //导入方法依赖的package包/类
@Override
protected Format getFormat(String pattern, Locale locale) {
DecimalFormat format = (DecimalFormat) super.getFormat(pattern,
locale);
format.setMaximumIntegerDigits(NUMBER_OF_INTEGER_PLACES);
format.setMaximumFractionDigits(NUMBER_OF_DECIMAL_PLACES);
// avoid lost precision due to parsing to double:
format.setParseBigDecimal(true);
return format;
}
示例6: getNumberFormat
import java.text.DecimalFormat; //导入方法依赖的package包/类
@Override
protected NumberFormat getNumberFormat(Locale locale) {
DecimalFormat format = (DecimalFormat) NumberFormat.getCurrencyInstance(locale);
format.setParseBigDecimal(true);
format.setMaximumFractionDigits(this.fractionDigits);
format.setMinimumFractionDigits(this.fractionDigits);
if (this.roundingMode != null && roundingModeOnDecimalFormat) {
format.setRoundingMode(this.roundingMode);
}
if (this.currency != null) {
format.setCurrency(this.currency);
}
return format;
}
示例7: toBigdecimal
import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
* Converts {@code inputValue} to bigdecimal value
*
* @param inputValue string to be converted to bigdecimal
* @param scale number of digits right of decimal point
* @return converted value of {@code inputValue} to bigdecimal
* if {@code inputValue} is null return null
* @throws ParseException if the specified string {@code inputValue}
* cannot be parsed.
*/
public static BigDecimal toBigdecimal(String inputValue, int scale) {
if (inputValue == null)
return null;
DecimalFormat decimalFormat = new DecimalFormat();
decimalFormat.setParseBigDecimal(true);
try {
return ((BigDecimal) decimalFormat.parse(inputValue)).setScale(scale, BigDecimal.ROUND_DOWN);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
示例8: amount
import java.text.DecimalFormat; //导入方法依赖的package包/类
@Test
public void amount() throws ParseException {
Money money = createObjectFromHtml(Money.class);
DecimalFormat format = new DecimalFormat("0,000.00");
format.setParseBigDecimal(true);
BigDecimal expected = (BigDecimal) format.parse("50,000.00");
assertEquals(money.amount, expected);
}
示例9: AbstractDishScraper
import java.text.DecimalFormat; //导入方法依赖的package包/类
AbstractDishScraper() {
decimalFormat = (DecimalFormat) NumberFormat.getInstance(Locale.GERMANY);
decimalFormat.setParseBigDecimal(true);
}