NumberFormat.getPercentInstance() does not work correctly for a double
value. The attached test works fine with jdk 1.4.2.
Platform
import java.text.*;
import java.util.*;
public class Test {
public static void main(String [] args) {
NumberFormat fmt = NumberFormat.getPercentInstance();
Test tt = new Test();
tt.doTest(fmt, new Double(9223372036854775808.0));
tt.doTest(fmt, new Double(-9223372036854775809.0));
}
public void doTest(NumberFormat fmt, Number value) {
String s = fmt.format(value);
String s2 = null;
Number n = null;
try {
n = fmt.parse(s);
s2 = fmt.format(n);
if (!s.equals(s2)) {
System.out.println("s is " + s);
System.out.println("s2 is " + s2);
System.out.println("FAIL");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Output:
--------
s is 922,337,203,685,477,600,000%
s2 is 922,337,203,685,477,580,700%
FAIL
s is -922,337,203,685,477,600,000%
s2 is -922,337,203,685,477,580,800%
FAIL
###@###.### 10/11/04 22:39 GMT
###@###.### 10/11/04 23:21 GMT
value. The attached test works fine with jdk 1.4.2.
Platform
import java.text.*;
import java.util.*;
public class Test {
public static void main(String [] args) {
NumberFormat fmt = NumberFormat.getPercentInstance();
Test tt = new Test();
tt.doTest(fmt, new Double(9223372036854775808.0));
tt.doTest(fmt, new Double(-9223372036854775809.0));
}
public void doTest(NumberFormat fmt, Number value) {
String s = fmt.format(value);
String s2 = null;
Number n = null;
try {
n = fmt.parse(s);
s2 = fmt.format(n);
if (!s.equals(s2)) {
System.out.println("s is " + s);
System.out.println("s2 is " + s2);
System.out.println("FAIL");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Output:
--------
s is 922,337,203,685,477,600,000%
s2 is 922,337,203,685,477,580,700%
FAIL
s is -922,337,203,685,477,600,000%
s2 is -922,337,203,685,477,580,800%
FAIL
###@###.### 10/11/04 22:39 GMT
###@###.### 10/11/04 23:21 GMT
- duplicates
-
JDK-6354557 DecimalFormat.parse() does not round correctly
-
- Closed
-
- links to
-
Review(master) openjdk/jdk/27563