0

I'm trying to get my python to convert a number given by the user in meters into inches, feet, and yards. When converting into inches it outputs 100*39.37 as 3936.9999999999995 which is clearly wrong. Anyone know why it's wrong and/or what I should change to make it correct?
Code:

measurement = int(input("How many meters do you want converting?"))
inches = measurement * 39.37
feet = inches / 12
yards = feet / 3
print("That is", inches ,"inches, ", feet,"feet and ", yards,"yards")
Baecon
  • 1
  • 1
    Because floating point numbers aren't always precise – Andrew Li Jun 28 '16 at 16:34
  • 1
    Instead of multiplying by `39.37`, multiply by [`decimal.Decimal('39.37')`](https://docs.python.org/3/library/decimal.html#decimal.Decimal) – Navith Jun 28 '16 at 16:35
  • 2
    You can clearly see a difference between 3936.9999999999995 and 3937 inches? Wow, [that's a pretty good eyesight](https://www.wolframalpha.com/input/?i=0.0000000000005+inches) :) – Łukasz Rogalski Jun 28 '16 at 16:36

0 Answers0