Q:

Rounding number up using .format()

I’m writing a simple program and I’m using .format() to round the number to 2 d.p. 
 State = 0.05
 County = 0.025
 Purchase = float(input(‘amount of purchase: ‘))
 State_tax = purchase * state
 County_tax = purchase * county
 Total_tax = state_tax + county_tax
 Total = purchase + total_tax
 Print(‘amount: ‘ + ‘{:.2f}’.format(purchase))
 Print(‘state tax: ‘ + ‘{:.2f}.format(state_tax))
 Print(‘county tax: ‘ + ‘{:.2f}.format(county_tax))
 Print(‘total tax: ‘ + ‘{:.2f}.format(total_tax))
 Print(‘total sale: ‘ + ‘{:.2f}.format(total))

To test it I inputted 11. However, the total doesn’t add up correctly to the tax. The total tax is 0.83 but the total is 11.82. It doesn’t round 11.825 to 11.83. How could I fix this?

A:

Because you are calculating tax total without formatting 
Try this one for tax as you shown in print
total_tax = float('{:.2f}'.format(state_tax)) + float('{:.2f}'.format(county_tax))

This fix fix your total

