print(math.ceil(1.2)) # 2
print(math.ceil(1.6)) # 2
print(math.ceil(-1.2)) # -1
print(math.ceil(-1.6)) # -1
print(math.ceil(45)) # 45
floor function returns highest integer lower than the input.
print(math.floor(1.2)) # 1
print(math.floor(1.6)) # 1
print(math.floor(-1.2)) # -2
print(math.floor(-1.6)) # -2
print(math.floor(45)) # 45
Comparison with round()print(round(3.5)) # Output: 4
print(math.ceil(3.5)) # Output: 4
print(math.floor(3.5)) # Output: 3
Ceiling for Time Estimation:
tasks = 3.4 # 3 hours 40 mins
print(math.ceil(tasks)) # Output: 4 (round up for scheduling)
Real-World Use Case: Price Roundingimport math
price = 59.99
discount = 0.2
discounted_price = math.floor(price * (1 - discount))
print(discounted_price) # Output: 47
We can use type() to get the data type.
import math
x = math.floor(-1.2)
print(x) # -2
print(type(x)) # <class 'int'>
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.