@Test public void parseDouble_withStringValue_shouldReturnDouble() throws Exception { assertThat(Numbers.parseDouble("0.01")).isEqualTo(0.01); assertThat(Numbers.parseDouble("-1015")).isEqualTo(-1015); }
public static Double parseDouble(final Object value) throws ClassCastException { if (value instanceof Number) { return ((Number) value).doubleValue(); } else if (value instanceof String) { try { return Double.valueOf((String) value); } catch (NumberFormatException e) { throw new ClassCastException("Unable to parse " + value + " as double."); } } else { throw new ClassCastException("Unable to parse " + value + " as double."); } }
Numbers { public static Double parseDouble(final Object value) throws ClassCastException { if (value instanceof Number) { return ((Number) value).doubleValue(); } else if (value instanceof String) { try { return Double.valueOf((String) value); } catch (NumberFormatException e) { throw new ClassCastException("Unable to parse " + value + " as double."); } } else { throw new ClassCastException("Unable to parse " + value + " as double."); } } }
Numbers { public static Double parseDouble(final Object value) throws ClassCastException { if (value instanceof Number) { return ((Number) value).doubleValue(); } else if (value instanceof String) { try { return Double.valueOf((String) value); } catch (NumberFormatException e) { throw new ClassCastException("Unable to parse " + value + " as double."); } } else { throw new ClassCastException("Unable to parse " + value + " as double."); } } private  Numbers(); }
Numbers { public static Double parseDouble(final Object value) throws ClassCastException { if (value instanceof Number) { return ((Number) value).doubleValue(); } else if (value instanceof String) { try { return Double.valueOf((String) value); } catch (NumberFormatException e) { throw new ClassCastException("Unable to parse " + value + " as double."); } } else { throw new ClassCastException("Unable to parse " + value + " as double."); } } private  Numbers(); static Double parseDouble(final Object value); }
Numbers { public static Double parseDouble(final Object value) throws ClassCastException { if (value instanceof Number) { return ((Number) value).doubleValue(); } else if (value instanceof String) { try { return Double.valueOf((String) value); } catch (NumberFormatException e) { throw new ClassCastException("Unable to parse " + value + " as double."); } } else { throw new ClassCastException("Unable to parse " + value + " as double."); } } private  Numbers(); static Double parseDouble(final Object value);  }