Summary of the round/Ceil/flodorf method in math

Source: Internet
Author: User
These three methods are a headache. After a burst of searches, We will summarize them as follows: Math. Round: If the parameter is a decimal number, rounding itself. Math. ceil: If the parameter is a decimal number, the smallest integer is obtained but not smaller than itself. math. floor: If the parameter is a decimal number, calculate the largest integer but not greater than itself. at the same time, pay attention to their return type: long round (double A) int round (float a) Double Ceil (double A) Double floor (double) Code As follows:
  1. Public ClassRoundtest {
  2. Public Static VoidMain (string [] ARGs ){
  3. Double[] Values = {-2.3,-1.0,0.25,4,1.5};
  4. For(IntI =0; I <values. length; I ++ ){
  5. System. Out. println (math. Round (Values [I]);
  6. System. Out. println (math. Ceil (Values [I]);
  7. System. Out. println (math. Floor (Values [I]); 
  8. System. Out. println ("============"+ I +"============");
  9. }
  10. }
  11. }

The returned results are as follows: -2-2.0-3.0 ============= 0 =================-1-1.0-1.0 ==== = ===== 44.04.0 ================= 3 ================= 22.01.0 ========= = 4 ================

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.