JDK-4139344 : java.text.DecimalFormat.applyPattern doesn't set minimum integer digits
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.2.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.5
  • CPU: sparc
  • Submitted: 1998-05-18
  • Updated: 1998-05-26
  • Resolved: 1998-05-26
Related Reports
Duplicate :  
Relates :  
Description

Name: dfC67450			Date: 05/18/98



java.text.DecimalFormat.applyPattern(String pattern) incorrectly sets minimum
integer digits in some cases.

Here is the test demonstrating the bug:

-----------------Test.java------------------------
import java.text.*;

public class Test {
    public static void main (String args[]){
        DecimalFormat df = new DecimalFormat();
        boolean passed = true;

        String patterns[] = {"#,#00.0##", "#,#00.00#", "#,#00.000", "#,#00.0"} ;
        int expectedMinIntDigits = 2;
        for (int i = 0; i < patterns.length; i++) {
          String pattern = patterns[i];
          System.out.println("Applying pattern: " + pattern);
          df.applyPattern(pattern);
          System.out.println("  new pattern :   " + df.toPattern());
          int minIntDigits = df.getMinimumIntegerDigits();
          System.out.println("  minIntegerDigits: " + minIntDigits);
          if (minIntDigits != expectedMinIntDigits) {
            System.out.println("  should be: " + expectedMinIntDigits);
            passed = false;
          }
          System.out.println();
        }
        if (passed) System.out.println("-- test passed --");
        else System.out.println("-- test failed --");

    }
}
---------Output from the test---------------------
Applying pattern: #,#00.0##
  new pattern :   #,#00.0##
  minIntegerDigits: 2
 
Applying pattern: #,#00.00#
  new pattern :   #,#00.00#
  minIntegerDigits: 2
 
Applying pattern: #,#00.000
  new pattern :   #00,000.000
  minIntegerDigits: 5
  should be: 2
 
Applying pattern: #,#00.0
  new pattern :   #,000.0
  minIntegerDigits: 3
  should be: 2
 
-- test failed --
--------------------------------------------------

======================================================================