How can I improve formatting of floats output from my tax calculator?
<p>I didn't have any problems writing this much, but the output numbers are a little wonky. Sometimes I'll get something like 83.78812, for example, and I'd rather round it up to 83.79.</p>

<p>Here's the code itself:</p>

<pre><code>#This is a simple tax calculator based on Missouri's tax rate.

while True:
tax = 0.076
cost = float(raw_input("How much does the item cost? $"))
taxAmount = tax * cost
final = taxAmount + cost
if cost &gt; 0:
    print "Taxes are $" + str(taxAmount) + "."
    print "The total cost is $" + str(final) + "."
else:
    print 'Not a valid number. Please try again.'
</code></pre>

<p>I've seen people mention that I should be using ints instead of floats, but my tax-rate is over three characters past the decimal. Furthermore, typing in a string results in an error that crashes the program, but I'd rather it simply give an error message and loop back to the beginning. I don't know how to fix either of these things.</p>

<p>You should use <strong>round</strong>:</p>

<pre><code>round(final,2)
</code></pre>

python python-2.7 calculator number-formatting