Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4218649

Float.valueOf () parses "1.d" but not "1.d2"

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.2.0
    • core-libs
    • generic
    • generic



      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)
      ======================================================================

            apalanissunw Anand Palaniswamy (Inactive)
            dblairsunw Dave Blair (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: