Home » Python

math.ceil() method with example in Python

Python math.ceil() method: Here, we are going to learn about the math.ceil() method with example in Python.
Submitted by IncludeHelp, on April 17, 2019

Python math.ceil() method

math.ceil() method is a library method of math module, it is used to get the ceil value of a given number, it accepts a number/numeric expression and returns the smallest integral value which is greater than the number.

Note: It is useful with the float values if the number is an integer value – it returns the same value.

Syntax of math.ceil() method:

    math.ceil(n)

Parameter(s): n – a number or numeric expression.

Return value: int – it returns an integer value – which is smallest integer value of given number but not less than the n.

Example:

    Input:
    n = 10.23

    # function call
    print(math.ceil(n))

    Output:
    11

Python code to find ceil value of a given number

# Python code to find ceil value of a given number
# importing math
import math

# number
n1 = 10.23
n2 = 10.67
n3 = 10
n4 = -10.23
n5 = 0

# printing ceil values
print("ceil(n1): ", math.ceil(n1))
print("ceil(n2): ", math.ceil(n2))
print("ceil(n3): ", math.ceil(n3))
print("ceil(n4): ", math.ceil(n4))
print("ceil(n5): ", math.ceil(n5))

Output

ceil(n1):  11
ceil(n2):  11
ceil(n3):  10
ceil(n4):  -10
ceil(n5):  0





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.