Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

controlling if the number is being rounded up or down in python

So I know how to round a number in python. It's fairly straightforward. But I'm wondering is there a way to round a random floating point up to the next integer. Or round it straight down. So if there was 8.7 to have the choice to bring it down to 8. Or if there was 8.3 to have the choice to bring it up to 9.

Because the number is a random floating point, i wont know whether it's 8.3 or 8.7 or 8.5 or 8.48237 but I always want it to round up to 9. Is this possible?

like image 657
Greg Peckory Avatar asked Dec 04 '25 05:12

Greg Peckory


1 Answers

You must be looking for math.ceil.

>>> from math import ceil
>>> ceil(8.3)
9.0
>>> ceil(8.48237)
9.0

ceil Function ->

ceil(...)
    ceil(x)

    Return the ceiling of x as a float.
    This is the smallest integral value >= x.
like image 170
Sukrit Kalra Avatar answered Dec 05 '25 18:12

Sukrit Kalra