by shigemk2

当面は技術的なことしか書かない

round

2.1 組み込み関数

x を小数点以下 n 桁で丸めた浮動小数点数の値を返します。

a = 3.14159

print round(a, 1) # 3.1
print round(a, 2) # 3.14
print round(a, 3) # 3.142
print round(a, 4) # 3.1416
print round(a, 0.5) # TypeError: 'float' object cannot be interpreted as an index