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

DecimalFormat: Negative format ignored

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • 9
    • 7u71
    • core-libs
    • x86_64
    • linux

      FULL PRODUCT VERSION :
      java -version
      java version "1.7.0_03"
      Java(TM) SE Runtime Environment (build 1.7.0_03-b04)
      Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux serverName 3.10.17 #1 SMP Tue Oct 29 10:41:00 CDT 2013 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Refer to bug report JDK-2017913 and JDK-4092480. Both of which are marked as fixed as of 1998.

      The bug is not fixed.
          


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
          dfFoo = new DecimalFormat("0000;-000");
          System.out.println(dfFoo.format(42));
          System.out.println(dfFoo.format(-42));
          System.out.println();

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
       0042
       -042
      ACTUAL -
       0042
       -0042

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.text.*;

      public class TestApp extends java.lang.Object
      {
        public static void main(java.lang.String[] args)
        {
          DecimalFormat dfFoo;
          
          dfFoo = new DecimalFormat("0000;-000");
          System.out.println(dfFoo.toPattern());
          System.out.println(dfFoo.format(42));
          System.out.println(dfFoo.format(-42));
          System.out.println();
          
          dfFoo.applyPattern("000;-000");
          System.out.println(dfFoo.toPattern());
          System.out.println(dfFoo.format(42));
          System.out.println(dfFoo.format(-42));
          System.out.println();
          
          dfFoo.applyPattern("000;-0000");
          System.out.println(dfFoo.toPattern());
          System.out.println(dfFoo.format(42));
          System.out.println(dfFoo.format(-42));
          System.out.println();
          
          dfFoo.applyPattern("0000;-000");
          System.out.println(dfFoo.toPattern());
          System.out.println(dfFoo.format(42));
          System.out.println(dfFoo.format(-42));
          System.out.println();
          
          
        }
          
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Define patterns for positive and negative.

          DecimalFormat dfPos = new DecimalFormat("0000");
          DecimalFormat dfNeg = new DecimalFormat("000");
          System.out.println(dfPos.format(42));
          System.out.println(dfNeg.format(-42));


      This produces the expected values.
      0042
      -042

            rgoel Rachna Goel (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: