2 / 3
is an integer operation, what you want is 2.0 / 3
which means I want to use floating point numbers.
What you consider an Intereger
is different from what you know from Maths. In programming languages it means that a result of an int-operation is allways an integer in itself.
In your example 2 / 3
is an integer-operation which means the result is rounded down to the nearest integer, which is zero. To avoid this indicate that at least one of your operands should be treates as some floating-point value, either using 2.0
or 2f
(alternativly 3.0
or 3f
).