Why is my float automatically rounding and how do i get it to stop
float pageCount = 10/6;
should be 1.666 but it is giving 1.0
Why is my float automatically rounding and how do i get it to stop
float pageCount = 10/6;
should be 1.666 but it is giving 1.0
Your calculation is being done in integer type since both the operands are of int
type
cast or mark atleast one of the operand as float.
float pageCount = 10/6f; //6f specifying 6 as float
or
float pageCount = ((float) 10)/6;
In your current form, both operands are of integer type and their division results in integer value that is why you get 1
not 1.666
Simple to the following 10.0/6