Python round up

Use the math ceil() function to round up in Python. This function returns the smallest integer higher or equal to `x`.

``````import math
math.ceil(x)``````

Note: The input should be float.

If you need an integer, call `int` to convert it:

``int(math.ceil(5.4))``

Python round-up example

A simple example code first imported the `math` module: `import math`. And passed the number into the `math.ceil()` method: `math.ceil(x)`.

`import matha = math.ceil(9.33333)print(a)b = math.ceil(0.16)print(b)`

Output:

How to round up a value with any decimal?

Answer: Use the `ceil` function:

``````import math

a = math.ceil(16.33333)
print(a)

b = math.ceil(17)
print(b)
``````

Output:

17
17

Round up to 2 decimal

```inputNumber = 3.367824

# rounding the number up to 2 decimal places
roundedNumber = round(inputNumber, 2)

# print the rounded value of floating-point number up to 2 decimals
print(roundedNumber)```

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