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

Decimal format of -1.0 with "#0.0000#;-#0.0#" gives "-1.0000"

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.2.0
    • core-libs
    • generic
    • solaris_2.6


      It appears that if a DecimalFormat pattern contains both a positive
      and negative subpattern, then the positive subpattern's fraction part is
      being used for negative numbers. Or something similar.

      Value -1.0 formatted with "#0.0000#;-#0.0#" results in "-1.0000".
      Should have been "-1.0".

      Simple test program:
      --------------------

      import java.text.DecimalFormat;

      public class DecimalFormatTest {

          private static void show(double d, String s) {
      String result = new DecimalFormat(s).format(d);
      System.out.println("Value " + d +
      " Format " + s +
      " Result '" + result + "'");
          }

          public static void main(String[] args) {
      show(-1.0, "#0.0000#;-#0.0#");
          }
      }

      -----------------------

      (423)# javac DecimalFormatTest.java
      (424)# java DecimalFormatTest
      Value -1.0 Format #0.0000#;-#0.0# Result '-1.0000'
      (425)# java -fullversion
      java full version "JDK-1.2fcs-B"
      (426)#

            aliusunw Alan Liu (Inactive)
            foliversunw Fred Oliver (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: