Take this code for example.
class Main {
public static void main(String[] args) {
int i = 41;
long l = i*9/5; //no explicit type casting required
float f = i*9/5; //no explicit type casting required
double d = i*9/5; //no explicit type casting required
double e = (double) i*9/5;
System.out.println("Int value "+i);
System.out.println("Long value "+l);
System.out.println("Float value "+f);
System.out.println("Double value "+d);
System.out.println("Double value cast "+e);
}
}
The target type is larger than the source type and hence no explicit casting is required but why is there a loss of precision? Why can't I get d
and f
as 73.8?