JDK-6609716 : DecimalFormat negative subpattern not according to specs.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-09-26
  • Updated: 2010-07-29
  • Resolved: 2007-10-01
Related Reports
Duplicate :  
Description
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 '#'.

Comments
EVALUATION This is a duplicate of 6594713.
01-10-2007