aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes == operator comparisons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "== operator comparisons" Watch "== operator comparisons" New topic
Author

== operator comparisons

Guangcheng Zhou
Greenhorn

Joined: Oct 13, 2006
Posts: 11
Hi all,

I was wondering why the following code is printing true and false.

double d1 = 2.5;
double d2 = 2.6;
System.out.println(d1 == 2.5f);
System.out.println(d2 == 2.6f);

Shouldn't they be printing the same boolean value at least?


Thanks,


Mack
sachin poddar
Greenhorn

Joined: Feb 10, 2006
Posts: 17
try this..
double d1= 2.5f;
double d2= 2.6f;
System.out.println(d1);
System.out.println(d2);
.. now i think you've got answer!


Sachin. [SCJP 1.4, SCWCD 5]
pranav thakker
Greenhorn

Joined: Nov 21, 2005
Posts: 20
I am still not getting this. Can any one explain why value of 2.6f is 2.5999999046325684 ???
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42590
    
  65
Check out the #21 in the Java Beginners FAQ. It links to articles that explain in detail what's going on.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: == operator comparisons