File tree 2 files changed +17
-0
lines changed
main/java/com/fasterxml/jackson/core/io
test/java/com/fasterxml/jackson/core/io
2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -306,6 +306,16 @@ public static double parseDouble(String s) throws NumberFormatException {
306
306
return Double .parseDouble (s );
307
307
}
308
308
309
+ /**
310
+ * @param s a string representing a number to parse
311
+ * @return closest matching float
312
+ * @throws NumberFormatException if string cannot be represented by a float
313
+ * @since v2.14
314
+ */
315
+ public static float parseFloat (String s ) throws NumberFormatException {
316
+ return Float .parseFloat (s );
317
+ }
318
+
309
319
public static BigDecimal parseBigDecimal (String s ) throws NumberFormatException {
310
320
return BigDecimalParser .parse (s );
311
321
}
Original file line number Diff line number Diff line change @@ -10,5 +10,12 @@ public void testNastySmallDouble()
10
10
final String nastySmallDouble = "2.2250738585072012e-308" ;
11
11
assertEquals (Double .parseDouble (nastySmallDouble ), NumberInput .parseDouble (nastySmallDouble ));
12
12
}
13
+
14
+ public void testParseFloat ()
15
+ {
16
+ final String exampleFloat = "1.199999988079071" ;
17
+ assertEquals (1.1999999f , NumberInput .parseFloat (exampleFloat ));
18
+ assertEquals (1.2f , (float )NumberInput .parseDouble (exampleFloat ));
19
+ }
13
20
}
14
21
You can’t perform that action at this time.
0 commit comments