Skip to content
Exercises · Q2

Q.How is math.ceil(89.7) different from math.floor(89.7)?

Punjab PsebTextbookSubjective· 2mImportance★★★★★est
50% · 20/40 Questions
✓ Free question

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)
Meaningsmallest integer ≥ 89.7largest integer ≤ 89.7
Directionrounds uprounds down
Result9089
Return typeintint
  • Both return an int (not a float), and both need import math.
  • For a whole-number input the two agree: math.ceil(7.0) and math.floor(7.0) are both 7.
Watch out

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").

✓Final answer

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.