JDK-8084348 : DecimalFormat Half_UP rounding mode does not work properly
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 8u40
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-06-03
  • Updated: 2015-06-09
  • Resolved: 2015-06-09
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :


A DESCRIPTION OF THE PROBLEM :
teh problem happens rounding a number using the DecimalFormat class using setRoundingMode method and formating. Teh result of this format using RoundigMode.HALF_UP results in a down rounding. The best way to describe the error is through an example.

Using this code:

DecimalFormat df = new DecimalFormat("#.00");
df.setRoundingMode(RoundingMode.HALF_UP);
String result = df.format(12.465d);

In java 6 result is 12.47
in java 8 result is 12.46

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The best way to describe the error is through an example.

Using this code:

DecimalFormat df = new DecimalFormat("#.00");
df.setRoundingMode(RoundingMode.HALF_UP);
String result = df.format(12.465d);


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
DecimalFormat df = new DecimalFormat("#.00");
df.setRoundingMode(RoundingMode.HALF_UP);
String result = df.format(12.465d);
---------- END SOURCE ----------