jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "== operator comparisons" Watch "== operator comparisons" New topic

== operator comparisons

Guangcheng Zhou

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?


sachin poddar

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

Sachin. [SCJP 1.4, SCWCD 5]
pranav thakker

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

Joined: Mar 22, 2005
Posts: 42959
Check out the #21 in the Java Beginners FAQ. It links to articles that explain in detail what's going on.
I agree. Here's the link: http://aspose.com/file-tools
subject: == operator comparisons
It's not a secret anymore!