import math
print(math.ceil(0.5))
戻りmath.ceil(0.5)math.ceil(1/2)とは異なる値を返す
1.0
しかし
import math
print(math.ceil(1/2))
戻り
0.0
何が起こっているのかここに?説明はいいだろう。
import math
print(math.ceil(0.5))
戻りmath.ceil(0.5)math.ceil(1/2)とは異なる値を返す
1.0
しかし
import math
print(math.ceil(1/2))
戻り
0.0
何が起こっているのかここに?説明はいいだろう。
あなたが明示的にfloat型にキャストする必要がのPython 2.xの使用してそのコードを実行しているようだ:あなたがする必要はありませんのpython 3.xのを実行する場合
import math
print(math.ceil(0.5))
print(math.ceil(float(1)/float(2)))
を明示的にそのキャストを行うと、あなたは同じ出力が得られます。
import math
print(math.ceil(0.5))
print(math.ceil(1/2))
ありがとう、ありがとう。 –
import math
print(math.ceil(1/float(2)))
この質問は、単に働くコードではなく、*説明*を探しています。あなたの答えは質問者のための洞察を提供せず、削除されるかもしれません。オスカーの観察の原因を説明するために[編集]してください。 –
'プリント(1/2)' ... [私は強制することができますどのようにDの –
可能な複製ivisionはPythonの浮動小数点ですか?](http://stackoverflow.com/questions/1267869/how-can-iforce-division-to-be-floating-point-in-python) –