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

DecimalFormat patterns lose negative suffix

XMLWordPrintable

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

      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 ----------

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: