当前位置:   article > 正文

python round函数_Python

python round函数_Python

Python round() 函数

描述

round() 方法返回浮点数x的四舍五入值。

语法

以下是 round() 方法的语法:

round( x [, n] )

参数

x -- 数值表达式。

n -- 数值表达式,表示从小数点位数。

返回值

返回浮点数x的四舍五入值。

实例

以下展示了使用 round() 方法的实例:

#!/usr/bin/python

print "round(80.23456, 2) : ", round(80.23456, 2)

print "round(100.000056, 3) : ", round(100.000056, 3)

print "round(-100.000056, 3) : ", round(-100.000056, 3)

以上实例运行后输出结果为:

round(80.23456, 2) : 80.23

round(100.000056, 3) : 100.0

round(-100.000056, 3) : -100.0

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/726419
推荐阅读
相关标签
  

闽ICP备14008679号