Numbers { public static double parseDouble(@Nullable String str) { if (str == null || str.isEmpty()) { return Double.NaN; } else { try { return Double.parseDouble(str); } catch (NumberFormatException e) { Exceptions.report(e); return Double.NaN; } } }  static boolean isReal(double value); static int pow(int x, int y); static double parseDouble(@Nullable String str); @Nullable static Double parseDoubleNull(@Nullable String str); static float parseFloat(@Nullable String str); static int parseInt(@Nullable String str, int defaultValue); static final DecimalFormat format2; static final DecimalFormat format3; static final DecimalFormat format6; }
@Test public void parseDouble() { assertEquals(-2, Numbers.parseDouble("-2"), 0.1); assertEquals(-1, Numbers.parseDouble("-1"), 0.1); assertEquals(0, Numbers.parseDouble("0"), 0.1); assertEquals(1, Numbers.parseDouble("1"), 0.1); assertEquals(2, Numbers.parseDouble("2"), 0.1); assertEquals(Double.NaN, Numbers.parseDouble(""), 0.1); assertEquals(0.0, Numbers.parseDouble("0.0"), 0.1); assertEquals(0.1, Numbers.parseDouble("0.1"), 0.1); assertEquals(Double.NaN, Numbers.parseDouble("X"), 0.1); assertEquals(Double.NaN, Numbers.parseDouble("NaN"), 0.1); assertEquals(Double.NaN, Numbers.parseDouble(null), 0.1); }