Best daily deals
Best daily deals

# How to round in Python

This quick tutorial shows users how to round in Python using one of three methods.
By
March 21, 2021

Want to know how to round in Python? This can be useful for a wide range of applications, particularly when converting a float into an integer, or when presenting data in a readable manner.

Thankfully, this is an easy job: there are actually three separate ways to round in Python.

## How to round in Python: know your options

First, you can use the built-in round() function. This will round values either up or down. math.floor(), meanwhile, will round the value down. Finally, math.ceil() will round the value up to the nearest whole.

In order to use the latter two statements, you will need to import the math module with the line: import math.

To see how this might work, use the following code:

Code
``````import math

number = 7.234

print(round(number))

print(math.floor(number))

print(math.ceil(number))``````

Now hit run, and you will see the output looks like so:

Code
``````7

7

8``````

As you can see, the first two options rounded down to 7, while the final option rounded up to 8. Remember: when using round(), the value will round up whenever the value is higher than .5.

## Other tricks using the math module

Now you know how to round in Python, there plenty of other neat things you can do with the math module. Some examples include:

• squrt() – Gets the square root of a number
• Math.sin() – Returns the sine of a number
• tan() – Returns the tangent of the number
• pi – Gives you pi