It is treating it as a double. However, you're assigning it to a float variable.
In some cases, C# and Java will allow implicit conversion; for example, the following is perfectly allowable:
class Main {
public static void main(String[] args) {
float c = 3.1e2f;
System.out.println(c);
double d = c;
System.out.println(d);
}
}
Since a double is a "larger" type than a float, there's no possibility of data loss if you do that.
However, if I try to do the following:
public class Main
{
public static void main(String[] args) {
double c = 3.1e2;
System.out.println(c);
float d = c;
System.out.println(d);
}
}
I end up getting the same compiler error you got. Again, that's because a double is a "larger" data type than a float, so the double could contain a value that's larger than the maximum possible value for a float. Consider the following code sample:
public class Main
{
public static void main(String[] args) {
double c = 10*(double)Float.MAX_VALUE;
System.out.println(c);
}
}
It prints 3.4028234663852886E39. Now, what would happen if I tried to put that in a float? Well, if I do the following, the result is Infinity:
public class Main
{
public static void main(String[] args) {
float c = 10*Float.MAX_VALUE;
System.out.println(c);
}
}
As you can see, the behaviors are quite different. If a conversion simply happened "in the background" without you being aware of it, you could get all kinds of unexpected results.
See also: Difference between implicit conversion and explicit conversion