- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do you round up a float number in Python?
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
- How to round down to 2 decimals a float using Python?
- How to round off a number in Python?
- Round float and double numbers in Java
- How to round off a floating number using Python?
- How do I correctly clean up a Python object?
- How to convert amount to float and round correctly in PHP?
- How do you append to a file with Python?
- How do you get the current figure number in Python's Matplotlib?
- How do you properly ignore Exceptions in Python?
- How do you create nested dict in Python?