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

[Fmt-Nu] Negative suffix ignored if negative subpattern doesn't match positive subpattern

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.0, 1.4.2, 5.0, 6
    • core-libs
    • generic, x86
    • generic, linux, windows_98, windows_xp



      Name: boT120536 Date: 12/05/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      The spec for DecimalFormat says that the negative subpattern is only used to
      determine the prefix and suffix for negative numbers:

      > That means that "#,##0.0#;(#)" produces precisely the same
      > behavior as "#,##0.0#;(#,##0.0#)".

      However, if you actually try this example, the negative suffix gets lost unless
      the two subpatterns match.

      import java.text.*;
      public class PatternTest
      {
      public static void main(String[] args)
      {
      DecimalFormat df = new DecimalFormat("#,##0.0#;(#,##0.0#)");
      System.out.println(df.toPattern());
      System.out.println(df.format(-1.5));

      DecimalFormat df2 = new DecimalFormat("#,##0.0#;(#)" );
      System.out.println(df2.toPattern());
      System.out.println(df2.format(-1.5));
      }
      }

      Output:
      #,##0.0#;(#,##0.0#)
      (1.5)
      #,##0.0#;(#,##0.0#
      (1.5
      (Review ID: 108474)
      ======================================================================

            nishjain Nishit Jain
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: