floor & ceil math functions
« All Math methods
ceil function returns lowest integer higher than the input.
Here are some examples with different type of numbers.
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
We can use type() to get the data type.
import math
x=math.floor(-1.2)
print(x) # -2
print(type(x)) # <class 'int'>
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com