0

I have a very basic question:

tip = input("What is the total of your bill? ")
tip = int(tip)

print("At 15% tip, you bill would come to:", tip * 1.15)

print("\nAt 20% tip, you're looking at paying:", tip *1.2)

print("Cheers, have a nice day!")
input("\n\nPress enter to exit")

So I tried this program out, I entered 50, at 20% it is fine it gives the correct value. But at 15%, it gives me 57.49999999999999. Did I do something wrong?

Yan Tsui
  • 1
  • 1
  • Looking into [floating point math](https://docs.python.org/2/tutorial/floatingpoint.html). – blacksite Jan 24 '17 at 13:34
  • 2
    You can *format* your floating point values to hide the inherent imprecision of floats: `print("At 15% tip, you bill would come to: {0:.2f}".format(tip * 1.15))` – Martijn Pieters Jan 24 '17 at 13:34

0 Answers0