Categories
Python Answers

How to round up a number with Python?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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