/** * Parses text to produce a numeric value. A {@link NumberFormatException} is * thrown if either the text is empty or if the parse does not consume all * characters of the text. * * @param text the string being parsed * @return a double value representing the parsed number * @throws NumberFormatException if the entire text could not be converted * into a double */ public double parse(String text) throws NumberFormatException { int[] pos = {0}; double result = parse(text, pos); if (pos[0] == 0 || pos[0] != text.length()) { throw new NumberFormatException(text); } return result; }
public Long parse(CharSequence object) throws ParseException { if ("".equals(object.toString())) { return null; } try { return (long) NumberFormat.getDecimalFormat().parse(object.toString()); } catch (NumberFormatException e) { throw new ParseException(e.getMessage(), 0); } } }
public Integer parse(CharSequence object) throws ParseException { if ("".equals(object.toString())) { return null; } try { return (int) Math.rint(NumberFormat.getDecimalFormat().parse(object.toString())); } catch (NumberFormatException e) { throw new ParseException(e.getMessage(), 0); } } }
public Double parse(CharSequence object) throws ParseException { if ("".equals(object.toString())) { return null; } try { return NumberFormat.getDecimalFormat().parse(object.toString()); } catch (NumberFormatException e) { throw new ParseException(e.getMessage(), 0); } } }
@Override public Double parse(String valueAsString) { return format.parse(valueAsString); } };
public Long parse(CharSequence object) throws ParseException { if ("".equals(object.toString())) { return null; } try { return (long) NumberFormat.getDecimalFormat().parse(object.toString()); } catch (NumberFormatException e) { throw new ParseException(e.getMessage(), 0); } } }
@Override public final Integer parse(final CharSequence pobject) throws ParseException { if (StringUtils.isEmpty(Objects.toString(pobject))) { return null; } try { return Integer.valueOf((int) NumberFormat.getFormat("###0").parse(pobject.toString())); } catch (final NumberFormatException e) { throw new ParseException(e.getMessage(), 0); // NOPMD, we needn't a stack trace } } }
@Override public Float parse(CharSequence object) throws ParseException { if ("".equals(object.toString())) { return null; } try { return (float) NumberFormat.getDecimalFormat().parse(object.toString()); } catch (NumberFormatException e) { throw new ParseException(e.getMessage(), 0); } }
@Override public BigDecimal parse(CharSequence object) throws ParseException { if ("".equals(object.toString())) { return null; } try { return BigDecimal.valueOf(NumberFormat.getDecimalFormat().parse(object.toString())); } catch (NumberFormatException e) { throw new ParseException(e.getMessage(), 0); } }
public Integer parse(CharSequence object) throws ParseException { if ("".equals(object.toString())) { return null; } try { return (int) Math.rint(NumberFormat.getDecimalFormat().parse(object.toString())); } catch (NumberFormatException e) { throw new ParseException(e.getMessage(), 0); } } }
@Override public final BigDecimal parse(final CharSequence pobject) throws ParseException { if (StringUtils.isEmpty(Objects.toString(pobject))) { return null; } try { return BigDecimal.valueOf(NumberFormat.getDecimalFormat().parse(pobject.toString())); } catch (final NumberFormatException e) { throw new ParseException(e.getMessage(), 0); // NOPMD, we needn't a stack trace } } }
public Double parse(CharSequence object) throws ParseException { if ("".equals(object.toString())) { return null; } try { return NumberFormat.getDecimalFormat().parse(object.toString()); } catch (NumberFormatException e) { throw new ParseException(e.getMessage(), 0); } } }
public Double parse(CharSequence object) throws ParseException { if ("".equals(object.toString())) { return null; } try { return NumberFormat.getDecimalFormat().parse(object.toString()); } catch (NumberFormatException e) { throw new ParseException(e.getMessage(), 0); } } }
@Override public final Long parse(final CharSequence pobject) throws ParseException { if (StringUtils.isEmpty(Objects.toString(pobject))) { return null; } try { return Long.valueOf((long) NumberFormat.getFormat("###0").parse(pobject.toString())); } catch (final NumberFormatException e) { throw new ParseException(e.getMessage(), 0); // NOPMD, we needn't a stack trace } } }
@Override public final BigDecimal parse(final CharSequence pobject) throws ParseException { if (StringUtils.isEmpty(Objects.toString(pobject))) { return null; } try { return BigDecimal.valueOf(NumberFormat.getCurrencyFormat().parse(pobject.toString())); } catch (final NumberFormatException e) { throw new ParseException(e.getMessage(), 0); // NOPMD, we needn't a stack trace } } }
@Override public BigInteger parse(CharSequence object) throws ParseException { if ("".equals(object.toString())) { return null; } try { return BigInteger.valueOf((long) NumberFormat.getDecimalFormat().parse(object.toString())); } catch (NumberFormatException e) { throw new ParseException(e.getMessage(), 0); } }
@Override public final Double parse(final CharSequence pobject) throws ParseException { if (StringUtils.isEmpty(Objects.toString(pobject))) { return null; } try { return Double.valueOf(NumberFormat.getCurrencyFormat().parse(pobject.toString())); } catch (final NumberFormatException e) { throw new ParseException(e.getMessage(), 0); // NOPMD, we needn't a stack trace } } }
@Override public BigDecimal parse(CharSequence object) throws ParseException { if ("".equals(object.toString())) { return null; } try { return BigDecimal.valueOf(NumberFormat.getDecimalFormat().parse(object.toString())); } catch (NumberFormatException e) { throw new ParseException(e.getMessage(), 0); } }
@Override public final Double parse(final CharSequence pobject) throws ParseException { if (StringUtils.isEmpty(Objects.toString(pobject))) { return null; } try { return Double.valueOf(NumberFormat.getCurrencyFormat().parse(pobject.toString())); } catch (final NumberFormatException e) { throw new ParseException(e.getMessage(), 0); // NOPMD, we needn't a stack trace } } }
private void formatValue() { if (!getStringValue().isEmpty()) { double parsedValue = NumberFormat.getDecimalFormat().parse(getStringValue()); getInputElement().asElement().value = NumberFormat.getDecimalFormat().format(parsedValue); } }