Name: dbT83986 Date: 03/09/99
Float.valueOf () parses the string "1.d" but not "1.d2". Here is
sample code:
public class NFETest {
public static void main (String args[]) {
String[] values = {"1.e", "1.e2", "1.d", "1.d2"};
for (int i=0; i<4; i++) {
try {
float x = Float.valueOf (values[i]).floatValue ();
System.out.println (values[i] + " parses to " + x);
}
catch (NumberFormatException nfe) {
System.out.println ("Cannot parse " + nfe.getMessage ());
}
}
} // main
}
Running this produces
Cannot parse 1.e
1.e2 parses to 100.0
1.d parses to 1.0
Cannot parse 1.d2
I believe that 1.d should not parse and that 1.d2 should parse.
(Review ID: 54565)
======================================================================
- duplicates
-
JDK-4023281 Conversion of string to double or float should tolerate trailing d, D, f or F
-
- Closed
-