0

I made this simple conversion function using Python a while ago, but now as I went over it, I just noticed how it returns: 100 * 8.8 = 880.0000000000001. It works when using any other values such as 10, 1000, etc. Could somebody please explain this to me?

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)

It returns:

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
martineau
  • 119,623
  • 25
  • 170
  • 301
vanDeurs
  • 35
  • 5

0 Answers0