pythonrounding

How to round to two decimal places in python?


Im trying to calculate a bill in python for hw. Cant figure out how to round the numbers to two decimal places. Here's what I have so far. Every time I try the round function, it doesnt work and gives me an error message. Help?!

ss_cost = 3.95 * 2
hb_cost = 8.95 * 2
ds_cost = 2.50 * 2
subtotal = (ss_cost) + (hb_cost) + (ds_cost)
tax = (round(subtotal * 0.0475), %.2)
print (tax)

Solution

  • You missplaced the %.2:

    tax = (round(subtotal * 0.0475, 2))
    

    And you don't need the %.