@Test public void testParseDouble() throws Exception { assertThat(NumberUtils.parse("0.", 2), is(0.0)); assertThat(NumberUtils.parse(".0", 2), is(0.0)); assertThat(NumberUtils.parse("0.0", 2), is(0.0)); assertThat(NumberUtils.parse("0.10", 2), is(0.10)); assertThat(NumberUtils.parse("0.10001", 2), is(0.10)); assertThat(NumberUtils.parse("1.10", 2), is(1.10)); assertThat(NumberUtils.parse("1.3", 2), is(1.30)); assertThat(NumberUtils.parse("1.33", 2), is(1.33)); assertThat(NumberUtils.parse("1.335", 2), is(1.34)); assertThat(NumberUtils.parse("-1.33", 2), is(-1.33)); assertThat(NumberUtils.parse("1,333", 2), is(1333.0)); assertThat(NumberUtils.parse("-1,333", 2), is(-1333.0)); assertNumberFormatException(""); assertNumberFormatException("."); }
public static double parse(String value, int decimalPlaces) throws NumberFormatException { value = value.replaceAll("[\\$,]", ""); double adjust = Math.pow(10, decimalPlaces); double parsed = Double.parseDouble(value); return Math.round(parsed * adjust) / adjust; }
NumberUtils { public static double parse(String value, int decimalPlaces) throws NumberFormatException { value = value.replaceAll("[\\$,]", ""); double adjust = Math.pow(10, decimalPlaces); double parsed = Double.parseDouble(value); return Math.round(parsed * adjust) / adjust; } }
NumberUtils { public static double parse(String value, int decimalPlaces) throws NumberFormatException { value = value.replaceAll("[\\$,]", ""); double adjust = Math.pow(10, decimalPlaces); double parsed = Double.parseDouble(value); return Math.round(parsed * adjust) / adjust; }  }
NumberUtils { public static double parse(String value, int decimalPlaces) throws NumberFormatException { value = value.replaceAll("[\\$,]", ""); double adjust = Math.pow(10, decimalPlaces); double parsed = Double.parseDouble(value); return Math.round(parsed * adjust) / adjust; }  static double parse(String value, int decimalPlaces); static String format(final long value); static String format(double value, int decimalPlaces); }
NumberUtils { public static double parse(String value, int decimalPlaces) throws NumberFormatException { value = value.replaceAll("[\\$,]", ""); double adjust = Math.pow(10, decimalPlaces); double parsed = Double.parseDouble(value); return Math.round(parsed * adjust) / adjust; }  static double parse(String value, int decimalPlaces); static String format(final long value); static String format(double value, int decimalPlaces);  }