What is the actual difference between round(), ceil(), and floor() in python, I am new to python and I want to know the difference of ceil() and floor() functions from the round() function?
any help is greatly appreciated
number = int(input("Enter number: "))
result = round(number)
#ceil()
#floor()
print(result)
>Solution :
round() – this function rounds a value according to the usual principle where if
the decimal place of a value is less than 5 it would be rounded by removing the decimal value whereas
if the decimal place is greater than 5 in value it will be rounded to the next value.
print(round(2.3)) #Output - 2
print(round(2.6)) #Output - 3
ceil() – this function round a value to the next value that comes after it ("ceil-ing" which denotes the roof (highest place))
import math #math function should be imported as function not built-in
print(math.ceil(2.3)) #Output - 3
print(math.ceil(2.6)) #Output - 3
floor() – here it does the opposite of what ceil() function did, you will understand by referring to the example ("floor" which denotes the ground(lowest place))
import math #math function should be imported as function not built-in
print(math.floor(2.3)) #Output - 2
print(math.floor(2.6)) #Output - 2