Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

How do you round up a float number in Python?

How do you round up a float number in Python?                                            


1 Answer
Jayashree

Python has an in-built function round() for this purpose. The function takes two arguments, the number to be rounded and the places upto which it is to be rounded. If the number is to be rounded to nearest integer, the second argument is not given.

>>> round(1.7456)
2
>>> round(1.4756)
1

If however, it is to be rounded up, 0.5 is added to it before rounding

>>> round(1.7456+0.5)
2
>>> round(1.4756+0.5)
2
Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.