All floating-point literals are assumed to be of type double, so 42e7 is a double.
Primitive assignment conversion:
1. A non-boolean may be converted to another non-boolean type, provided the conversion is a widening conversion.
2. A non-boolean may not converted to another non-boolean type, if the conversion would be a narrowing conversion.
Therefore
float i = 345; --> integer 345 is converted to a float
supplement:
char-->int-->long-->float-->double
^
I
byte-->short
The arrow --> shows the allowed widening conversion.
Reverse order need casting.
e.g.
int i = (int)123f;
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.