Python-number-round
提供:Dev Guides
Python Number round()メソッド
説明
Pythonの数値メソッド* round()*は、小数点からn桁に丸められたxを返します。
構文
以下は* round()*メソッドの構文です-
round( x [, n] )
パラメーター
- x -これは数値式です。
- n -これも数値式です。
戻り値
このメソッドは、小数点から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