Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the difference between round(), ceil(), and floor() in python?

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading