-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
8, 8u45, 9
-
x86_64
-
windows_7
FULL PRODUCT VERSION :
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
If I am using rounding half down, and have a number that ends with 5(half), then the output of the formattor will be incorrect.
For example:
new DecimalFormat("#,##0.0000");
Double toFormat = 10.55555;
the output will be 10.5556, and I am expecting 10.5555.
REGRESSION. Last worked in version 7u75
ADDITIONAL REGRESSION INFORMATION:
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a DecimalFormat like this:
DecimalFormat format = new DecimalFormat("#,##0.0000");
Set rounding half down
format.setRoundingMode(RoundingMode.HALF_DOWN);
Give this number to format:
Double toFormat = 10.55555;
Call the method format(Object obj) on the formatter
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
10.5555
ACTUAL -
10.5556
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package testjava8;
import java.math.RoundingMode;
import java.text.DecimalFormat;
/**
* Created by cristian.nandrean on 6/11/2015.
*/
public class Formatori {
public static void main(String[] args) {
DecimalFormat format = new DecimalFormat("#,##0.0000");
format.setRoundingMode(RoundingMode.HALF_DOWN);
Double toFormat = 10.55555;
System.out.println("Round down");
System.out.println(format.format(toFormat));//working BAD (is a BUG)
format.setRoundingMode(RoundingMode.HALF_UP);
toFormat = 10.55555;
System.out.println("Round up");
System.out.println(format.format(toFormat));//working GOOD
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
There isn't one.
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
If I am using rounding half down, and have a number that ends with 5(half), then the output of the formattor will be incorrect.
For example:
new DecimalFormat("#,##0.0000");
Double toFormat = 10.55555;
the output will be 10.5556, and I am expecting 10.5555.
REGRESSION. Last worked in version 7u75
ADDITIONAL REGRESSION INFORMATION:
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a DecimalFormat like this:
DecimalFormat format = new DecimalFormat("#,##0.0000");
Set rounding half down
format.setRoundingMode(RoundingMode.HALF_DOWN);
Give this number to format:
Double toFormat = 10.55555;
Call the method format(Object obj) on the formatter
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
10.5555
ACTUAL -
10.5556
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package testjava8;
import java.math.RoundingMode;
import java.text.DecimalFormat;
/**
* Created by cristian.nandrean on 6/11/2015.
*/
public class Formatori {
public static void main(String[] args) {
DecimalFormat format = new DecimalFormat("#,##0.0000");
format.setRoundingMode(RoundingMode.HALF_DOWN);
Double toFormat = 10.55555;
System.out.println("Round down");
System.out.println(format.format(toFormat));//working BAD (is a BUG)
format.setRoundingMode(RoundingMode.HALF_UP);
toFormat = 10.55555;
System.out.println("Round up");
System.out.println(format.format(toFormat));//working GOOD
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
There isn't one.
- relates to
-
JDK-8066560 (fmt) Formatter printf rounding error (double rounding up) for double values close to but below tie
- Open