したがって、float として関数にインポートされる数値を丸める単純な方程式があります。インポートされた数値が53.3
「整数」として認識されるはずですが、フロートとして設定しなかった場合はそうではなく、「。」があるため整数として設定した場合に備えて。
何か案は?
def cm(centimeter):
result = round(centimeter / 100, 2)
print ("%d centimeters is the same as %d meters." % (centimeter, result))
print (result)
cent=input("Centimeters: ")
cm(float(cent))
問題は、これが出力されることです:
Centimeters: 53.6
53 centimeters is the same as 0 meters.
0.54
次のようになります。
Centimeters: 53.6
53.6 centimeters is the same as 0.54 meters.
プリント(結果)を取り出しました、悪いです。結果が 0.54 として出力される方法を確認してはならない場合でも、それでも 0 メートルに丸められます。