Skip to content

Python integer division round up

Use integer arithmetic to get integer division round-up in Python. There is a simple technique for converting integer floor division into ceiling division:

Python integer division round up

A simple example code performs ceiling division in integer arithmetic. Here is a way to divide that round upwards if there is a non-zero remainder.

1 box can contain 10 items. So if the items typed by the user are 102 then the code should return 11 boxes.

items = 102
boxsize = 10
num_boxes = (items + boxsize - 1)

print("No of boxed", num_boxes)


Python integer division round up

Do comment if you have any doubts or suggestions on this Python division topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

1 thought on “Python integer division round up”

Leave a Reply

Your email address will not be published. Required fields are marked *