First, the original intention:
Sometimes we need to calculate the number of pages when we display the data on the page. is generally rounded up, such as counts=205 pagecouts=20, pages= 11 pages.
The general division is only the integer part, which does not reach the requirement.
Second, the method:
1. General Division:
Up (A/b) = Int ((a+b-1)/b)
Take the critical value, calculate the range of the a+b-1 is OK.
2. Python Division:
The first thing to say is the division in Python, where there are two divisions in Python version 2.5, the so-called true division and floor division.
when using the X/Y form for division operations, if Y and X. Are all shaped, then the operation will intercept the result, taking the integer part of the operation, such as 2/3, the result of the operation is 0; if one of the X and Y is a floating-point number, then the so-called true division, such as the result of 2.0/3, is 0.66666666666666663.
Another division is in the form of x//y (rounding down), then the so-called floor division, that is, the maximum integer value is not greater than the result, this operation is independent of the operand. For example, the result of 2//3 is that the result of 0,-2//3 is -1,-2.0//3-1.0.
In Python 3.0, X/y will only perform a true division, regardless of the operand; x//y performs floor division.
If you need to use this in the 2.5 version of Python, you will need to include the declaration of the From __FUTURE__ Import division before the code. Such as:
from __future__ Import Division a=2/3
At this point, the result of variable a will be 0.66666666666666663 instead of the original 0.
Python arithmetic Up Rounding Method: (a+b-1)/b
3. Python Match.ceil function
The ceil (x) function is rounded up, taking the nearest integer greater than or equal to X.
Import Math
Math.ceil (Float (205)/20)
In addition: Rounding down, generally using floor Division, General Division/,round () round function.
Python algorithm for rounding up