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(4.2)))

to call math.ceil with a number to round it up.

Then we call int to convert the rounded up number 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 *