This is the way the language is defined. You divide an int
by an int
, so the calculation is performed resulting in an int
, giving 3
(truncating, rather than rounding).
You then store 3
into a float
, giving 3.0
.
If you want the division performed using float
s, make (at least) one of the arguments a float
, e.g. 360f / 100
. In this way, they other argument will be converted to a float
before the division is performed.
360 / 100f
will work equally well, but I think it probably make sense to make it clear as early as possible that this is a floating point calculation, rather than an integral one; that's a human consideration, rather than a technical one.
(Note that 360.0
is actually a double
, although using that will work as well. The division would be performed as a double
, then the result converted to a float
for the assignment).