JDK-8152933 : Rounding error in NumberFormat
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 8,9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2016-03-28
  • Updated: 2016-11-28
  • Resolved: 2016-04-01
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_72"
Java(TM) SE Runtime Environment (build 1.8.0_72-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.72-b15, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
CentOS release 5.3 (Final)

A DESCRIPTION OF THE PROBLEM :
The following code is supposed to print "1.235". In stead, it prints "1.234"

NumberFormat nf = NumberFormat.getInstance();
nf.setRoundingMode(RoundingMode.HALF_UP);
nf.setMaximumFractionDigits(3);
System.out.println(nf.format(1.2345));


REGRESSION.  Last worked in version 7u80

ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0_72"
Java(TM) SE Runtime Environment (build 1.8.0_72-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.72-b15, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code in description field


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
NumberFormat nf = NumberFormat.getInstance();
nf.setRoundingMode(RoundingMode.HALF_UP);
nf.setMaximumFractionDigits(3);
System.out.println(nf.format(1.2345));

---------- END SOURCE ----------


Comments
Attached test case executed on : JDK 7u80 - Pass (output - 1.235) JDK 8 - Fail (output - 1.234) JDK 8u74 - Fail (output - 1.234) JDK 9ea - Fail (output - 1.234)
29-03-2016