In both cases your code is going to compare a float value to a double, as the compiler sees 4.2f as a float and 4.2 (without the f) as a double.
* The float data type is a single-precision 32-bit
* The double data type is a double-precision 64-bit
You shouldn´t ever compare floats or doubles for equality, you can´t really assure that the number you assign to the float or double is exact.
By default java assumes a manually specified number to be a double, as a double would more precisely cover more numbers that you could type in. You have to cast between doubles and float explicitly.
* A float is a 32 bit IEEE 754 floating point.
* A double is a 64 bit IEEE 754 floating point.
so it is just a matter of precision because neither of the fraction portions .8 and .65 have a terminating binary representation, so there is some rounding error. the double has more precision so it has slightly less rounding error.
5