Easy to confuse some of the math method descriptions

Source: Internet
Author: User

1. Math.Round

Returns a close integer value, which is actually what we call rounding a decimal.

/**   * Returns the nearest parameter of long  */staticlong round (double  a)/**    */static int round (float a) 

Examples are as follows:

    1. Math.Round (8.1): 8
    2. Math.Round (8.4): 8
    3. Math.Round (8.5): 9
    4. Math.Round (8.9): 9
    5. Math.Round (-8.1): 8
    6. Math.Round (-8.4): 8
    7. Math.Round ( -8.5):-8// negative numbers are different from integers. When the first decimal point is less than or equal to 5, carry is carried , so get-8
    8. Math.Round (-8.9):-9//when the first decimal place is greater than 5 o'clock, the loft is carried out. 9 is the next integer less than-8, so get-9
2. Math.floor

is actually the double type that returns the maximum integer value that is not greater than the parameter.

/***/staticdouble floor (double  a  )

Examples are as follows:

Math.floor (8.9): 8.0
Math.floor (8.1): 8.0
Math.floor (-8.1): 9.0
Math.floor (-8.9): 9.0

3. Math.ceil

In contrast to Math.floor, the double type that returns the smallest integer value that is not less than the parameter.

/***/staticdouble ceil (double a)  

Examples are as follows:

Math.ceil (8.9): 9.0
Math.ceil (8.1): 9.0
Math.ceil (-8.1): 8.0
Math.ceil (-8.9): 8.0

Easy to confuse some of the math method descriptions

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.