带有Python示例的math.ceil()方法

Python math.ceil() 方法

math.ceil()方法数学模块的库方法,用于获取给定数字的ceil值,它接受数字/数字表达式并返回大于该数字的最小整数值。

注意:如果数字是整数值,则对于浮点值很有用–它返回相同的值。

它的语法 math.ceil() 方法:

    math.ceil(n)

Parameter(s): n-一个数字或数字表达式。

返回值: int –返回整数值,该整数值是给定数字的最小整数值,但不小于n。

示例

    Input:
    n = 10.23

    # 函数调用
    print(math.ceil(n))

    Output:
    11

Python代码查找给定数字的ceil值

# Python代码查找给定数字的ceil值
# 导入数学
import math

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

# 打印值
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))

输出结果

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