This week's book giveaway is in the OCAJP forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
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

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
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: 810

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

wood burning stoves
subject: why float == long