"Java" Java.lang.Math:public Static long round (double a) and public static int round (float a)

Source: Internet
Author: User

1  PackageMath;2 3  Public classTestmath_round {4      Public Static voidMain (string[] args) {5SYSTEM.OUT.PRINTLN (Math.Round (0.5));//16System.out.println (Math.Round (-0.5));//07System.out.println (Math.Round (-0.501));//-18         //the Math class rounding method round for negative operations when the decimal place is greater than 0.5 to carry, less than or equal to 0.5 not rounding9     }Ten}
View Code

1  PackageMath;2 3 ImportJava.math.BigDecimal;4 5 classmyround{6      Public Static DoubleDivDoubleDintScale ) {7BigDecimal b1=NewBigDecimal (d);8BigDecimal b2=NewBigDecimal (1);9         returnb1.divide (B2, scale, bigdecimal.round_half_up). Doublevalue ();Ten     } One } A  Public classTestmath_round { -      Public Static voidMain (string[] args) { -SYSTEM.OUT.PRINTLN (Math.Round (0.5));//1 theSystem.out.println (Math.Round (-0.5));//0 -System.out.println (Math.Round (-0.501));//-1 -         //the Math class rounding method round for negative operations when the decimal place is greater than 0.5 to carry, less than or equal to 0.5 not rounding -System.out.println (Myround.div (-0.5, 0));//-1.0 +         //after the improvement for the usual rounding.  -     } +}
improved usually rounded

"Java" Java.lang.Math:public Static long round (double a) and public static int round (float a)

Related Article

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.