-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.2.0
-
sparc
-
solaris_2.5
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 --
--------------------------------------------------
======================================================================
- duplicates
-
JDK-4134300 DecimalFormat bug added in 1.1.6
-
- Closed
-
- relates to
-
JDK-4101481 java.text.DecimalFormat.applyPattern doesn't set minimum integer digits
-
- Closed
-