BigDecimal's round_half_up and Round_half_down

Source: Internet
Author: User

http://esffor.javaeye.com/blog/96157

ROUND_HALF_UP: When encountering. 5 of the case, the upper approximation, example: 1.5->;2
Round_half_down: When encountering. 5, approximate, example: 1.5->;1

BigDecimal a = new BigDecimal (1.5);
System.out.println ("down=" +a.setscale (0,bigdecimal.round_half_down) + "/tup=" +a.setscale (0,bigdecimal.round_half _UP));
Results: Down=1 up=2
See this example to understand!

Additional parameter description

Round_ceiling
If BigDecimal is positive, do round_up operation; if negative, do round_down operation.
Round_down
Increments the number before the decimal is not discarded (that is, truncated).
Round_floor
If the BigDecimal is positive, then it is round_up; if negative, it is round_down.
Round_half_down
If you discard part > 5, make round_up; otherwise, make round_down.
Round_half_even
If the left digit of the discard part is odd, then it is round_half_up; if it is an even number, it is round_half_down.
Round_half_up
If part >=.5 is discarded, it is round_up; otherwise, it is round_down.
Round_unnecessary
The pseudo-rounding mode actually indicates that the required operation must be accurate, so no rounding is required.
Round_up
  always adds numbers before non-  0   Discard decimals (that is, truncate).      

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.