我之前使用Python制作了这个简单的转换函数,但现在当我查看它时,我只是注意到它的返回方式:100 * 8.8 = 880.0000000000001
。它在使用10
,1000
等任何其他值时都有效。有人可以向我解释一下吗?
def converting_currency(usd):
currency = input("What currency do you have? ('KR' or 'EU')")
if currency == 'KR':
amount = usd * 8.8
print("If you have", + usd, "dollars, you have", + amount, "kronor")
elif currency == 'EU':
amount = usd * 10.5
print("If you have", + usd, "euros, you have", + amount, "kronor")
converting_currency(100)
它返回:
What currency do you have? ('KR' or 'EU')KR
If you have 100 dollars, you have 880.0000000000001 kronor
Process finished with exit code 0