Originally posted by kumar shyam:
the conversion between long to float is allowed in java, the size of long is 64 were as the size of the float is 32 how is it possible, would'nt there be loss in the data, plz give me adetailed explanation.
if possible with as example.
If you convert one type of data into another the rules of casting must be followed. If with conversion you lose precision, as when converting an int to a byte, then you will get a compiler error unless you explicitly cast.
A data type with fewer bits can be converted to a type with more bits without explicit casting. When you downcast a value of a wider type the upper bytes will be truncated.
So for example, the lowest order byte in the int value will be copied to the byte value.
In the case of long to float conversion where the target allows for bigger numbers a large value in the long type value that uses all 64 bits will lose some of the lower bits when converted to float since the exponent uses 8 bits of the 32 provided for float values.
I hope this helps
Greetings,
Gian Franco