The
three methods that are available in the math class relate to rounding:
first one: Ceil
Ceil means: The meaning of the ceiling; The method indicates that the value of the Math.ceil (11.3) upward is 12; Math.ceil. (-11.6) The result is-11; the second one is: Floor
First of all his English meaning is the meaning of the floor, which means that the downward rounding,
The result of Math.floor (11.6) is 11;
Math.floor (-11.4); The result is -12. The third is: round
He said rounding, the algorithm is Math.floor (x+0.5), that is, add 0.5 to the original number and then proceed down the rounding;
Math.Round (11.5), i.e. Math.floor (11.5+0.5) = Math.floor (12) = 12;
Similarly: Math.Round ( -11.5) = Math.floor ( -11.5+0.5) =math.floor (-11.0) =-11; Conclusion:
Conclusion: After the decimal point is greater than 5, the decimal point is less than and equal to 5, and is more than 5 of the rounding
That is to say: After the decimal point is greater than 5 all add, equal to 5 positive plus, less than 5 all do not add
Self-feel, or use Math.floor (x+0.5) way to memory, plus 0.5 after the whole line down!