0

On this forum a lot of people said, that when we make for example:

float a=1.0; and not float a=1.0f;

that the compiler is thinking that 1.0 is a double. But why is that possible?

Float has only 32bits, a double number has 64bit!

So when we say without a f the compiler says that is a double it is not logical because the float variable has not enough space for the double, you now what I mean?

That is not logical or?

qoidewjo
  • 3
  • 2
  • 1
    Because the Java Language Specification says that a floating-point number literal is by default interpreted as a `double`, not a `float`. In other words, `0.0` is the same as writing `0.0d`. – Slaw Dec 12 '21 at 01:15
  • Java defines double is the "default type" of an unspecified floating-point literal – Hovercraft Full Of Eels Dec 12 '21 at 01:16
  • I now but my program compiles when I make float test=1;, when now really java interpreted this as a double, that make not sense, because a float cannot have a double in his available space – qoidewjo Dec 12 '21 at 01:17
  • Writing `float f = 1;` is not the same thing as `float f = 1.0;`, because `1` is an `int`, not a `double`. – Slaw Dec 12 '21 at 01:17
  • Oh you are right That was my problem, I dont tried it with ja float number hahahahaha, and java saw it as a int and said automatically it is correct, beaucse of auto cast – qoidewjo Dec 12 '21 at 01:18
  • 1
    Side note about, *"On this forum..."* -- this is not and has never been a forum – Hovercraft Full Of Eels Dec 12 '21 at 02:27

0 Answers0