float, '%.2f' help... please!

William Dandreta wjdandreta at worldnet.att.net
Wed Jun 28 11:32:51 EDT 2000


Hi chiba,

Here is a method I sometimes use to do that.

roundedPriceTimes100 = int((price+.005)*100))
roundedPrice = roundedPriceTimes100[:-2]+'.'+roundedPriceTimes100[-2:]

chibaA at TinterlogD.Tcom wrote in message
<39596682.108805343 at news1.on.sympatico.ca>...
>Hi,
>
>I'm just kinda stuck for answers...  I need to display a price -
>rounded up to the proper cent.  I was using this line:
>
>print '%.2f' % (price+0.005)
>
>Thinking that it would just chop off the float at the second decimal.
>But when I had a value of 0.00 for price, it seemed to round up.  To
>be sure, I wanted to find a method of printing that would just chop
>off any decimals after 2 - and NOT round up or down.  Is there such a
>method?
>
>Thanks!





More information about the Python-list mailing list