1

I am having a problem with rounding the final result to 2 decimal places in Python. It always shows up only 1 decimal. eg 33.6$ I want to have it as 33.60$

    #tip calculator
bill = float (input("what is the total bill? "))
tip = float (input ("percentage tip 10%, 20% etc. ? "))
ppl = int (input ("number of people to split the bill? "))

tip_decimal = tip/100+1
calc = (bill/ppl)*tip_decimal
calc2 = round(calc, 2)
print(f"each person should pay {calc2}$")
ninja06
  • 19
  • 4
  • 1
    Does this answer your question? [How to round to 2 decimals with Python?](https://stackoverflow.com/questions/20457038/how-to-round-to-2-decimals-with-python) – Justin May 07 '22 at 17:23

1 Answers1

3

use formating here.

bill = float (input("what is the total bill? "))
tip = float (input ("percentage tip 10%, 20% etc. ? "))
ppl = int (input ("number of people to split the bill? "))

tip_decimal = tip/100+1
calc = (bill/ppl)*tip_decimal # change calc2 to calc in print
# calc2 = round(calc, 2) # you also not need this line of code.
print(f"each person should pay {calc:.2f}$") # here `:.2f` add zero at end if there is no second digit
codester_09
  • 5,622
  • 2
  • 5
  • 27