You have to convert the types to floats first.
In general, if you have some non-float numeric types (such as int
s) a
and b
, in order to get a float division you use float32(a)/ float32(b)
(or float64
as the case may be). This applies to any other numeric type too, if you want to treat floats as integers or integers as complex numbers convert the operands. In this case, if a is 3 and b is 2, float32(a)/float32(b)
will be 1.5.
If you want integer division to be done, but the result to be a float, then covert the result as in float32(a/b)
. In this case, if a is 3 and b is 2, then float32(a/b)
will get you 1.0.