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

DecimalFormat looses closing parenthesis when using (#) as negative subpattern

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 7u25
    • core-libs
    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.7.0_25"

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      Hello,

      The following test case does not produce the same output twice contrarily to what the DecimalFormat javadoc says:

      import java.text.DecimalFormat;

      public class Test {

          public static void main(String[] args) throws Exception {
              String pattern1 = "#,##0.0#;(#)";
              String pattern2 = "#,##0.0#;(#,##0.0#)";
              DecimalFormat format1 = new DecimalFormat(pattern1);
              System.out.println(pattern1 + " -> " + format1.format(-1000));
              DecimalFormat format2 = new DecimalFormat(pattern2);
              System.out.println(pattern2 + " -> " + format2.format(-1000));
          }

      }

      Ouput is:

      #,##0.0#;(#) -> (1,000.0
      #,##0.0#;(#,##0.0#) -> (1,000.0)

      Notice the missing closing parenthesis.

      Best regards,

      Thomas Leplus

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the following piece of code:

      import java.text.DecimalFormat;

      public class Test {

          public static void main(String[] args) throws Exception {
              String pattern1 = "#,##0.0#;(#)";
              String pattern2 = "#,##0.0#;(#,##0.0#)";
              DecimalFormat format1 = new DecimalFormat(pattern1);
              System.out.println(pattern1 + " -> " + format1.format(-1000));
              DecimalFormat format2 = new DecimalFormat(pattern2);
              System.out.println(pattern2 + " -> " + format2.format(-1000));
          }

      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      #,##0.0#;(#) -> (1,000.0)
      #,##0.0#;(#,##0.0#) -> (1,000.0)
      ACTUAL -
      #,##0.0#;(#) -> (1,000.0
      #,##0.0#;(#,##0.0#) -> (1,000.0)

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class Test {

          public static void main(String[] args) throws Exception {
              String pattern1 = "#,##0.0#;(#)";
              String pattern2 = "#,##0.0#;(#,##0.0#)";
              DecimalFormat format1 = new DecimalFormat(pattern1);
              System.out.println(pattern1 + " -> " + format1.format(-1000));
              DecimalFormat format2 = new DecimalFormat(pattern2);
              System.out.println(pattern2 + " -> " + format2.format(-1000));
          }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use the full pattern instead of (#).

            rgoel Rachna Goel (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: