Take float f = 1.65f
an example
Improvement arrangement
Math.ceil(f) //2.0
Round down
Math.floor(f) //1.0
rounding
Math.rint(f) //2.0
When float f = 2.5f
, the following result is rounded and we hope there are some differences.
Math.rint(f) //2.0
Math.rint
.5
When it encounters an even result, the return value of the above three methods are all double
types.
Using the Math.round
result of rounding the return value int
, 2.5f
the return value 3
.