What am I missing?
float stepSize = 0.0f;
int activeCircleRadius = 10;
int numSteps = 24;
AiLog.v(\"init activeCircleRadius \" + activeCircleRadius + \" numStep
Here both variables are integers so you are performing integer division:
activeCircleRadius / numSteps
The result of integer division is an integer. The result is truncated.
To fix the problem, change the type of one (or both) variables to a float
:
float stepSize = 0.0f;
float activeCircleRadius = 10;
Or add a cast to float in the division expression:
stepSize = (float)activeCircleRadius / numSteps;
Don't do integer division
stepSize = activeCircleRadius / (float)numSteps;
In summary: Yes its because you divide activeCircleRadius by an integer.
an integer division will give the result as 0. its 10/24 and not 10.0/24.0. you need to make one variable as double or float to get non zero answer.
You are doing an integer division, and hence will not get any decimal places in your answer. Try changing:
stepSize = activeCircleRadius / numSteps;
to
stepSize = activeCircleRadius / (float)numSteps;
With all arithmetic operators in Java, the result has the type of the largest operator. For instance:
- float operator long => float
- int operator int => int
- int operator long => long
float stepSize = 0f;
float activeCircleRadius = (float) 10.0;
int numSteps = 24;
stepSize = activeCircleRadius / numSteps;