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

DecimalFormat does not work as described in the javadoc.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.2
    • core-libs

      FULL PRODUCT VERSION :
      java version "1.4.2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
      Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux java 2.4.21-215-default

      A DESCRIPTION OF THE PROBLEM :
      The following

      import java.text.DecimalFormat;

      /*
       *
       */
      public class DecimalFormatTest {

          public static void main(String[] args) {
              Double aDouble = new Double(-123.123);
              DecimalFormat aFormat = new DecimalFormat("###,##0.0##;(#)");
              DecimalFormat aFormat2 = new DecimalFormat("###,##0.0##;(###,##0.0##)");
              System.out.println("aFormat " + aFormat.format(aDouble));
              System.out.println("aFormat2 " + aFormat2.format(aDouble));
          }
      }

      produces the following

      aFormat (123.123
      aFormat2 (123.123)

      Note the misssing closing paren on the aFormat line.

      According the the javadoc both formats should produce identical output.
      from teh javadoc .
      ----
      If there is an explicit negative subpattern, it serves only to specify the negative prefix and suffix; the number of digits, minimal digits, and other characteristics are all the same as the positive pattern. That means that "#,##0.0#;(#)" produces precisely the same behavior as "#,##0.0#;(#,##0.0#)".
      -------

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run the code shown above.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      aFormat (123.123 )
      aFormat2 (123.123)
      ACTUAL -
      aFormat (123.123
      aFormat2 (123.123)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.text.DecimalFormat;

      /*
       *
       */
      public class DecimalFormatTest {

          public static void main(String[] args) {
              Double aDouble = new Double(-123.123);
              DecimalFormat aFormat = new DecimalFormat("###,##0.0##;(#)");
              DecimalFormat aFormat2 = new DecimalFormat("###,##0.0##;(###,##0.0##)");
              System.out.println("aFormat " + aFormat.format(aDouble));
              System.out.println("aFormat2 " + aFormat2.format(aDouble));
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      usr the full negative pattern.

            peytoia Yuka Kamiya (Inactive)
            okutsu Masayoshi Okutsu
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: