-1

I am trying to do a tip calculator and I need it to print 2 decimals, but when I run the program and the result is a whole number, it doesn´t show the decimals. How do I do it?

print("Welcome to the tip calculator")
bill = float(input("What was the total bill? "))
tip = input("What percentage tip would you like to give? 10, 12, or 15? ")
people = input("How many people to split the bill? ")
bill_pp = float(float(bill)/float(people))
bill_pp_wtip = (float(bill_pp)*float(1+float(float(tip)/100)))
print(f"Each person should pay: ${(bill_pp_wtip)}")

This is what I get with whole numbers, only 1 decimal

1 Answers1

0

You can format the float in the f-string:

print(f"Each person should pay: ${bill_pp_wtip:.2f}")
DarkKnight
  • 19,739
  • 3
  • 6
  • 22