JDK-6609719 : DecimalFormat patterns lose negative suffix
  • 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 :
java version "1.5.0_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Using the DecimalFormat(String) constructor:

If the pattern contains a negative sub-pattern that does not exactly reproduce the positive sub pattern (with prefix/suffix) the suffix of the negative patten is lost.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the program that's given below.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected the close paren to appear as the negative suffix for every pattern.
ACTUAL -
in pat #0.0#;(0) out pat #0.0#;(#0.0# neg prefix ( neg suffix  -1.1 (1.1
in pat #0.0;(#) out pat #0.0;(#0.0 neg prefix ( neg suffix  -1.1 (1.1
in pat #0.0#;(#) out pat #0.0#;(#0.0# neg prefix ( neg suffix  -1.1 (1.1
in pat #0.0#;(#0.0#) out pat #0.0#;(#0.0#) neg prefix ( neg suffix ) -1.1 (1.1)

REPRODUCIBILITY :
This bug can be reproduced always.

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

class DecimalFormatPlay {
  public static void main (String[] args) {
    String[] pats = {
      "#0.0#;(0)", "#0.0;(#)", "#0.0#;(#)",
      "#0.0#;(#0.0#)"
    };
    for (int i = 0; i < pats.length; i++) {
      String s = pats[i];
      DecimalFormat df = new DecimalFormat(s);
      System.out.println("in pat " + s +
                         " out pat " + df.toPattern() +
                         " neg prefix " + df.getNegativePrefix() +
                         " neg suffix " + df.getNegativeSuffix() +
                         " -1.1 " + df.format(-1.1));
    }
  }
}

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

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