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

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: P3
    • None
    • Affects Version/s: 1.2.0
    • Component/s: 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)
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: