Omkar onky wrote:In SCJP kathy seirra book, kathy mentioned: a float value never equals to double value, in comparison always we get false.
If that is correct what about this code?
I think you might want to double-check what she
actually said in the book, because if she did, then it's plainly wrong - as you have conclusively proved. In most comparisons involving numeric types of different sizes, the smaller one will be converted to the larger
before the comparison takes place, and since floating-point numbers are notorious for not holding
exact values - particularly for fractions involving 10ths - the
double version will be different from a
float expanded to a
double.
I suspect that if you try:
System.out.println( 0.75 == 0.75f );
and
System.out.println( 0.0625 == 0.0625f );
you'll find that they print out true as well.
I suggest you read
this. It may well help to explain some of this stuff.
Winston