[Fmt-De] Different scientific notation parsing between Float and NumberFormat

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P5
    • None
    • Affects Version/s: 6u10
    • Component/s: core-libs

      FULL PRODUCT VERSION :
      java version "1.6.0_18"
      Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
      Java HotSpot(TM) 64-Bit Server VM (build 16.0-b13, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux xxx 2.6.31.9-174.fc12.x86_64 #1 SMP Mon Dec 21 05:33:33 UTC 2009 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Parsing a number in scientific notation using Float accepts the exponent as either 'e' or 'E' where NumberFormat does not.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      package test;

      import java.text.NumberFormat;
      import java.text.ParseException;

      public class TestNumberFormat {

      public static void main(String[] args) throws ParseException {
      NumberFormat fmt = NumberFormat.getNumberInstance();
      System.out.println(fmt.parse("9.0e-05"));
      System.out.println(fmt.parse("9.0E-05"));
      System.out.println(Float.parseFloat("9.0e-05"));
      System.out.println(Float.parseFloat("9.0E-05"));
      }

      }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      9.0E-5
      9.0E-5
      9.0E-5
      9.0E-5
      ACTUAL -
      9
      9.0E-5
      9.0E-5
      9.0E-5

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      Use Float.parseFloat() instead of NumberFormat.parse()

            Assignee:
            Justin Lu
            Reporter:
            Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: