3

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?

Greg Peckory
  • 7,700
  • 21
  • 67
  • 114

1 Answers1

4

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.
Sukrit Kalra
  • 33,167
  • 7
  • 69
  • 71