File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

why float == long

amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
Hi

can any body please tell me why in code
5.0==5L

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
amit


Thanks and Regards, Amit Taneja
Akash Roy
Greenhorn

Joined: Jan 08, 2005
Posts: 16
Hi,
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

Regards,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why float == long