本文整理匯總了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);
}