Q.How is math.ceil(89.7) different from math.floor(89.7)?
Both functions convert a float to a nearby integer but in opposite directions: math.ceil(89.7) rounds up to 90, math.floor(89.7) rounds down to 89.
The idea. The math module gives two one-sided rounding functions. For any number x, ceil(x) ("ceiling") is the smallest integer greater than or equal to x, and floor(x) is the largest integer less than or equal to x. They bracket x from above and below.
import math
print(math.ceil(89.7)) # -> 90
print(math.floor(89.7)) # -> 89
Expected output
90
89
Point-by-point comparison
math.ceil(89.7) | math.floor(89.7) | |
|---|---|---|
| Meaning | smallest integer ≥ 89.7 | largest integer ≤ 89.7 |
| Direction | rounds up | rounds down |
| Result | 90 | 89 |
| Return type | int | int |
- Both return an
int(not a float), and both needimport math. - For a whole-number input the two agree:
math.ceil(7.0)andmath.floor(7.0)are both 7.
Neither function is "rounding to the nearest integer" — that is round(). For 89.2, ceil still gives 90 and floor gives 89, whereas round(89.2) gives 89. Also note the behaviour on negatives: math.floor(-89.7) is −90 and math.ceil(-89.7) is −89 (down means "more negative").
math.ceil(89.7) returns 90 because ceil rounds up to the smallest integer not below the number, while math.floor(89.7) returns 89 because floor rounds down to the largest integer not above it.
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.