Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

This problem is killing me. How does one roundup a number UP in Python?

I tried round(number) but it rounds the number down. Example:

round(2.3) = 2.0 and not 3, what I would like

Then I tried int(number + .5) but it rounds the number down again! Example:

int(2.3 + .5) = 2

Then I tried round(number + .5) but it won't work in edge cases. Example:

WAIT! THIS WORKED!

Please advise.

1 Answer

0 votes
by (106k points)

For round a floating-point number in Python you can use the ceil function see the code below:-

import math 

print(math.ceil(4.2))

To know more about this you can have a look at the following video tutorial:-

Related questions

Browse Categories

...