📜  Python| math.ceil()函数

📅  最后修改于: 2022-05-13 01:54:20.076000             🧑  作者: Mango

Python| math.ceil()函数

在Python中,数学模块包含许多数学运算,可以使用该模块轻松执行。 math.ceil()函数返回大于数字的最小整数值。如果 number 已经是整数,则返回相同的数字。

Syntax: math.ceil(x)

Parameter:
x: This is a numeric expression.

Returns:  Smallest integer not less than x.

代码#1:

# Python code to demonstrate the working of ceil()
    
# importing "math" for mathematical operations 
import math 
    
x = 33.7
    
# returning the ceil of 33.7
print ("The ceil of 33.7 is : ", end ="") 
print (math.ceil(x))
输出:
The ceil of 33.7 is : 34


代码#2:

# Python code to demonstrate the working of ceil()
    
# importing "math" for mathematical operations 
import math 
    
# prints the ceil using ceil() method 
print ("math.ceil(-13.1) : ", math.ceil(-13.1))
print ("math.ceil(101.96) : ", math.ceil(101.96))
输出:
math.ceil(-13.1) :  -13
math.ceil(101.96) :  102