Math. Round (doublevalue) = [Add a half-floor shape long]

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.