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 '#'.
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 '#'.
- duplicates
-
JDK-6594713 [Fmt-De] DecimalFormat incorrectly formats values if the negative subpattern is (#)
-
- Closed
-