2017-07-08から1日間の記事一覧

Python3の四捨五入

Pythonの四捨五入は思った挙動をしないことがある。多分、丸め込みが原因。 In [1]: round(2.5, 0) Out[1]: 2.0 In [2]: round(2.0, 0) Out[2]: 2.0 In [3]: round(3.5, 0) Out[3]: 4.0 四捨五入はDecimalを使用したほうがいい。 from decimal import Decima…