JDK-8228976 : Output of float operation as String gives inconsistent results
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 11,13,14
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2019-07-28
  • Updated: 2019-08-01
  • Resolved: 2019-08-01
Related Reports
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
using java 12.0.1

A DESCRIPTION OF THE PROBLEM :
System.out.println(4+3.14f+"aabc"); gives 7.1400003aabc but
System.out.println(5+3.14f+"aabc"); gives 8.14aabc     why?


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run System.out.println(4+3.14f+"aabc"); 
      

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
7.14aabc
ACTUAL -
7.1400003aabc

---------- BEGIN SOURCE ----------
public class TestInt{

	public static void main(String args[]){

		System.out.println(5+3.14f+"aabc");

	}
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Resolving as a duplicate of JDK-4511638. The patch proposed for JDK-4511638 gives the correct result.
01-08-2019

To reproduce the issue, run the attached test case : JDK 11.0.3- Fail JDK 13-ea + 30 - fail JDk 14-ea+7 - Fail Output of the statements System.out.println(new BigDecimal(4 + 3.14f)); System.out.println(new BigDecimal(5 + 3.14f)); is consistent . 7.14000034332275390625 8.14000034332275390625 But with the following System.out.println(4+3.14f); System.out.println(5+3.14f); output is 7.1400003 8.14
01-08-2019