I am dividing 2 numbers and want to return a decimal when appropriate. But it is returning whole number on everything.
float temp = (twoMileInSeconds - 774) / 6;
timeIndex = (int)Math.floor(temp);
debug1.setText("Before rounding: " + temp);
debug2.setText("After rounding: " + timeindex);
Thanks
What data type is 'twomileinsecods' ? If its int, then that is the problem... or maybe if you put 6.0 instead of 6.
To ensure that the division taking place to the right of the equals sign results in a float, make sure all data types on the right are already floats. The problem is that it's casting to float AFTER the division has already taken place.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments