Why does the compiler does this narrowing conversion.
Pls. provide more details.
Joined: Aug 03, 2002
Java performs the following conversions when appropriate:
byte -> short -> long -> float -> double
(char is left out on purpose)
If one of the terms in a binary expression is a floating point number (float or double) then the other term will be converted to a floating point number so that floating point arithmetic can be performed.
The long variable l will be converted to float because a long lies within the range of a float even though the number will lose out on precision.
It's up to the programmer to allocate appropriate types to the variables if greater precision or ranges are desired. I have seen more use of doubles than floats for primitive variable types.