cannot convert from double to float
Casting from a double to a float can be done like this:
double d = 1.2;float f = (float) d;
Or if you just need to express 1.2
as a float to start with, then use 1.2f
.
Note
float
is single-precision 32-bit anddouble
is double-precision 64-bit so it is possible to lose precision in the conversion. See the primitive data types documentation.