Return the floating point value x rounded to n digits after the decimal point. If n is omitted, it defaults to zero. The result is a floating point number. Values are rounded to the closest multiple of 10 to the power minus n; if two multiples are equally close, rounding is done away from 0 (so. for example, round(0.5) is 1.0 and round(-0.5) is -1.0).
根据埃德温的回答推断:
使用:
Python包含
round()
函数,该函数lets you specify您需要的位数。从文档中:所以您需要使用
round(x, 2)
来进行正常舍入。为了确保数字总是向上舍入您需要使用ceil(x)
函数。同样,要将向下取整使用floor(x)
。见:} documentation } documentation -你可能还是想看看这个,以备将来参考
^{
^{
相关问题 更多 >
编程相关推荐