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

java.text.DecimalFormat.applyPattern doesn't set minimum integer digits

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5

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

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              aliusunw Alan Liu (Inactive)
              Reporter:
              dfazunensunw Dmitri Fazunenko (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: