Implementation of Java division result with decimal and progressive method

Source: Internet
Author: User

http://blog.csdn.net/windone0109/article/details/5355379 into a method: that is, the omission of the bit as long as greater than 0 to go into a bit;
Rounding Method: That is, the omission of the bit less than five are to be shed, but the omission of the bit on the full five to go into a bit;
There is also a
To the end of the law: that is omitted in the position whether or not full five are to be shed;

1. Divide with decimals

For example:

int a = 8;
int b = 3;
int c = ((double) LA)/b;

System.out.println (c);

System Printed: 2.6666666666666665

2, the realization of the progressive method

Implemented with Math.ceil (), such as Math.ceil (2.1), the result is 3.0

For example:

int a = 8;
int b = 3;
int c = ((double) LA)/b;

int d = (int) math.ceil (c);

System.out.println (d);

System printed: 3

Implementation of Java division result with decimal and progressive method

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.