Summary of some methods of rounding (Java)

Source: Internet
Author: User

The math class provides three methods for rounding:ceil, Floor, andround, which correspond to the meanings of their English names, for example, theEnglish meaning of Ceil is the ceiling, which means rounding up, so, The result of Math.ceil (11.3) is that the result of 12,math.ceil (-11.3) is -11;floor, the English meaning is the flooring, the method is to be rounded down, so,Math.floor (11.6) The result of 11,math.floor (-11.6) is the result of -12; The most difficult to master is the round method, which means "rounding ", the algorithm is Math.floor (x+0.5), The original number is added to 0.5 and then rounded down, so theresult of Math.Round (11.5) is Math.Round, andThe result of the (-11.5) is -11.

Summary of some methods of rounding (Java)

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.