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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P5 P5
    • None
    • 6u10
    • 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()

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: