「Python」math.floorメソッドで切り捨てを行うサンプル

2020年12月12日

説明
math.floor(x)
x の「床」 (x 以下の最大の整数) を返します。 x が浮動小数点数でなければ、内部的に x.__floor__() が実行され、 Integral 値が返されます。

サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
#!/usr/bin/python3
import math
cftA = 34.37
print("result1: ",math.floor(cftA))
cftB = 78.75
print("result2: ",math.floor(cftB))
# coding: utf-8 #!/usr/bin/python3 import math cftA = 34.37 print("result1: ",math.floor(cftA)) cftB = 78.75 print("result2: ",math.floor(cftB))
# coding: utf-8

#!/usr/bin/python3

import math

cftA = 34.37
print("result1: ",math.floor(cftA)) 

cftB = 78.75
print("result2: ",math.floor(cftB))

実行結果
>python test.py
result1: 34
result2: 78

Python

Posted by arkgame