How to round up a number with Python?

Sometimes, we want to round up a number with Python.

In this article, we’ll look at how to round up a number with Python.

How to round up a number with Python?

To round up a number with Python, we can use the math.ceil method.

For instance, we write:

import math

print(int(math.ceil(5.2)))

Then we see 6 is printed since we call math.ceil to round 5.2 up to the nearest integer.

And then we use int to convert the float returned by math.ceil to an integer.

Conclusion

To round up a number with Python, we can use the math.ceil method.