I haven't used the math class for a long time. I cannot remember it clearly, so that I can make mistakes when I read a scjp question. I will refresh my memory today. Remember!
Public class t {public static void main (string [] ARGs) {system. out. println (math. round (-4.1); system. out. println (math. round (-4.8); system. out. println ("---"); system. out. println (math. ceil (-4.8); system. out. println (math. floor (-4.8 ));}}
This sectionCodeOutput:
-4-5----4.0-5.0
About Ceil and floor:
1. Ceil is the ceiling, that is, it is up to the big, for example, 2.1 and 2.9 are enough to 3;-2.1 and-2.9 are enough to-2; because it is big enough.
2. The floor is the floor, that is, the floor is smaller, such as 2.1 and 2.9-> 2;-2.1 and-2.9->-3; because it is small enough;
3. the return value is the same as the original value type, or double;
---------------------------------------- Split line of dead skin -------------------------------------------
Math. Round (double:
1. -- double returns long; float returns int;
2. -- the rounding formula is the parameter (long) math. Floor (a + 0.5d) -- that isPlus half floor shape long!