In Processing I have this code:
int numberOfSteps = 20;
float numberOfStepsCalculated = (1/20);
println(numberOfStepsCalculated);
But my print keeps returning 0.0
I can not figure out why!
Thanks for my dumb question
In Processing I have this code:
int numberOfSteps = 20;
float numberOfStepsCalculated = (1/20);
println(numberOfStepsCalculated);
But my print keeps returning 0.0
I can not figure out why!
Thanks for my dumb question
Integer divison.
float numberOfStepsCalculated = (1.0f / numberOfSteps); // 20
When you divide two int
(s) the result is an int
(or 0
). You then widen the result to a float
(or 0.0
). Promote one of the values in the calculation to a float
and you'll get a float
result.