Because an int
fits inside a long
, but if you put a double
inside a float
you may lose precision (it's a narrower type).
If you really must you can force this via casting
double d = 4.0;float f = (float)d; // this is allowed
Because an int
fits inside a long
, but if you put a double
inside a float
you may lose precision (it's a narrower type).
If you really must you can force this via casting
double d = 4.0;float f = (float)d; // this is allowed