round()方法返回 x 的小數點四舍五入到n個數字。
語法
以下是round()方法的語法:
round( x [, n] )
參數
x --這是一個數值表達式 n --這也是一個數值表達式返回值
該方法返回 x 的小數點四舍五入到n個數字
例子
下面的例子顯示了round()方法的使用
#!/usr/bin/pythonprint "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.23round(100.000056, 3) : 100.0round(-100.000056, 3) : -100.0
新聞熱點
疑難解答