Skip to content

Ceiling division Python

  • by

You need to import math and use math.ceil to Ceiling division in Python. There is no operator which divides with ceil.

math.ceil(x)

Ceiling division Python

A simple example code that rounds a number UP to the nearest integer, if necessary, and returns the result.

import math

# Round a number upward to its nearest integer
print(math.ceil(2.4))
print(math.ceil(7.3))
print(math.ceil(-1.3))
print(math.ceil(10.0))

Output:

Ceiling division Python

What does it mean to round up?

When you round up a number you round the number to the closest integer that is greater than the number. Because of this, when you round 7.3 up, it returns 8.

Do comment if you have any doubts or suggestions on this Python deviation 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.

Leave a Reply

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