math.ceil带小数点_Python中带有示例的math.ceil()方法

math.ceil带小数点

Python math.ceil()方法 (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.

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

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()方法的语法:

    math.ceil(n)

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

参数: n-数字或数字表达式。

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

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

Example:

例:

    Input:
    n = 10.23

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

    Output:
    11

Python代码查找给定数字的ceil值 (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


翻译自: https://www.includehelp.com/python/math-ceil-method-with-example.aspx

math.ceil带小数点

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值