If I’m not mistaken,
0.5
are decimal numbers; thus, making it a float value.
You should not rely solely on your intuition when learning a new programming language.
In fact, 0.5
is a double
literal. For a float
literal you need to write 0.5f
.
As The Java Language Specification (JLS 3.10.2) states:
A floating-point literal is of type
float
if it is suffixed with an ASCII letterF
orf
; otherwise its type isdouble
and it can optionally be suffixed with an ASCII letterD
ord
.
See also: