List of usage examples for java.text DecimalFormat parseObject
public Object parseObject(String source) throws ParseException
From source file:net.pms.util.Rational.java
/** * Parses the specified {@link String} and returns a {@link BigDecimal} * using the specified {@link DecimalFormat}. {@code value} is expected to * be without leading or trailing whitespace. If {@code value} is blank, * {@code null} will be returned./*from ww w . j a v a2s.co m*/ * * @param value the {@link String} to parse. * @param decimalFormat the {@link DecimalFormat} to use when parsing. * @return The resulting {@link BigDecimal}. * @throws NumberFormatException If {@code value} cannot be parsed. */ @Nullable public static BigDecimal parseBigDecimal(@Nullable String value, @Nullable DecimalFormat decimalFormat) { if (StringUtils.isBlank(value)) { return null; } if (decimalFormat != null) { decimalFormat.setParseBigDecimal(true); try { return (BigDecimal) decimalFormat.parseObject(value); } catch (ParseException e) { throw new NumberFormatException("Unable to parse \"" + value + "\": " + e.getMessage()); } } return new BigDecimal(value); }