Python函数-round() 函数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python函数-round() 函数相关的知识,希望对你有一定的参考价值。

round( x [, n]  )
功能:
round() 方法返回浮点数x的四舍五入值。
x-数值表达式。n-数值表达式。返回浮点数x的四舍五入值。

实例:
1 #!/usr/bin/python
2 
3 print "round(80.23456, 2) : ", round(80.23456, 2)
4 print "round(100.000056, 3) : ", round(100.000056, 3)
5 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

 

 





以上是关于Python函数-round() 函数的主要内容,如果未能解决你的问题,请参考以下文章