Numbers { public static float parseFloat(@Nullable String str) { if (str == null || str.isEmpty()) { return Float.NaN; } else { try { return Float.parseFloat(str); } catch (NumberFormatException e) { Exceptions.report(e); return Float.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 parseFloat() { assertEquals(-2, Numbers.parseFloat("-2"), 0.1); assertEquals(-1, Numbers.parseFloat("-1"), 0.1); assertEquals(0, Numbers.parseFloat("0"), 0.1); assertEquals(1, Numbers.parseFloat("1"), 0.1); assertEquals(2, Numbers.parseFloat("2"), 0.1); assertEquals(Float.NaN, Numbers.parseFloat(""), 0.1); assertEquals(0.0, Numbers.parseFloat("0.0"), 0.1); assertEquals(0.1, Numbers.parseFloat("0.1"), 0.1); assertEquals(Float.NaN, Numbers.parseFloat("X"), 0.1); assertEquals(Float.NaN, Numbers.parseFloat("NaN"), 0.1); assertEquals(Float.NaN, Numbers.parseFloat(null), 0.1); }