File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why float == long 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 "why float == long" Watch "why float == long" New topic

why float == long

amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 812

can any body please tell me why in code

then answer is true !!!
I know variables contains bits representing the value and here above 5.0 ( i think its double ) is equal to 5 ( long ) why ?
is it because both are 64 bits..

but what about long store decimals in bits.. how it can be same ?
pls reply

thanx and regards

Thanks and Regards, Amit Taneja
Akash Roy

Joined: Jan 08, 2005
Posts: 16
During == operator i think long gets promoted to float as 5.0 and hence the == operator returns true. The same can be observed during comparisons of the following types:=

int == long
short == byte
float ==double

I agree. Here's the link:
subject: why float == long
It's not a secret anymore!