[Tutor] Rounding Error

Michael Lewis mjolewis at gmail.com
Sat Jan 28 07:01:34 CET 2012


Update

I am trying to round a float to two decimals.
>
> Basically, I am writing a program to ask a user how many square feet they
> need to paint. I then calculate how many cans of paint they need and will
> also show the total purchase price. I've tried this two ways, and both ways
> I am semi-successful meaning that my output is rounding but it displays a
> number of zero's after the number rounds. How can I make the zero's stop
> displaying?
>



>         total = PRICE_PER_CAN * cans + (PRICE_PER_CAN * cans * TAX)
>         total = round(total,2)
>         print 'For %d square feet, you\'ll need %d cans of paint.'
> %(square_feet, cans)
>         print 'That will cost you $%f.' %(total)
>
>
>
>         total = PRICE_PER_CAN * cans + (PRICE_PER_CAN * cans * TAX)
>         print 'For %d square feet, you\'ll need %d cans of paint.'
> %(square_feet, cans)
>         print 'That will cost you $%f.' %round(total,2)
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120127/ca11af15/attachment.html>


More information about the Tutor mailing list