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

java.text.DecimalFormat.parse() fails when ParseIntegerOnly set to true

XMLWordPrintable

    • 1.2.2
    • sparc
    • solaris_2.5



      Name: dfC67450 Date: 09/02/98



      java.text.DecimalFormat.parse(String text, ParsePosition pp) incorrectly parses
      "-0.0" if setParseIntegerOnly(true) has been called previously. According to
      javadoc output value of parse should be integer.

      Javadoc about NumberFormat.setParseIntegerOnly:
         "Sets whether or not numbers should be parsed as integers only."


      This bug was introduced in JDK1.2-fcsH.
       
      Here is the test demonstrating the bug:

      -----------------Test.java------------------------
      import java.text.*;

      public class Test {
          public static void main (String args[]){
              DecimalFormat df = new DecimalFormat();
              df.setParseIntegerOnly(true);
              Number n = df.parse("-0.0", new ParsePosition(0));
              if (n instanceof Double) {
                System.out.println("Test failed");
                System.out.println(" parse(\"-0.0\") returns " + n);
                System.out.println(" should return integer value");
              } else {
                System.out.println("Test passed");
                System.out.println(" parse(\"-0.0\") returns " + n);
              }
          }
      }

      ---------Output from the test (JDK1.2-fcsH) ---------------------
      Test failed
        parse("-0.0") returns -0.0
        should return integer value
      ---------Output from the test (JDK1.2-fcsG) ---------------------
      Test passed
        parse("-0.0") returns 0
      --------------------------------------------------

      ======================================================================

            aliusunw Alan Liu (Inactive)
            dfazunensunw Dmitri Fazunenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: