1. 程式人生 > >Python函數-round() 函數

Python函數-round() 函數

div spa ont ted bin 浮點 方法 表達式 size

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() 函數