JDK-6609653 : DecimalFormat does not work as described in the javadoc.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2007-09-26
  • Updated: 2010-07-29
  • Resolved: 2007-10-01
Related Reports
Duplicate :  
Description
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.

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