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

DecimalFormat negative subpattern not according to specs.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • core-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      According to the Javadoc, a pattern like "0.00;(#)" should be the same as "0.00;(0.00)". However, I wrote a unit-test that shows different and everything after the '#' is not included in the result.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Add the following unit-test to a JUnit or TestNG testcase:

          public void testJavaDecimalFormat() {
              DecimalFormat format = new DecimalFormat("0.00;(0.00)");
              assertEquals("5.00", format.format(new Integer(5)));
              assertEquals("(5.00)", format.format(new Integer(-5)));

              format = new DecimalFormat("0.00;(#)");
              assertEquals("5.00", format.format(new Integer(5)));
              assertEquals("(5.00)", format.format(new Integer(-5)));
          }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected were no failures.
      ACTUAL -
      The last assertEquals fails with the message:
      expected <(5.00)> but was <(5.00>


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
          public void testJavaDecimalFormat() {
              DecimalFormat format = new DecimalFormat("0.00;(0.00)");
              assertEquals("5.00", format.format(new Integer(5)));
              assertEquals("(5.00)", format.format(new Integer(-5)));

              format = new DecimalFormat("0.00;(#)");
              assertEquals("5.00", format.format(new Integer(5)));
              assertEquals("(5.00)", format.format(new Integer(-5)));
          }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Write the negative subpattern completely, don't rely on the single '#'.

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: