Decimal formatting

mensanator at aol.com mensanator at aol.com
Thu Sep 13 16:59:07 EDT 2007


On Sep 13, 3:50 pm, Harlin Seritt <harlinser... at yahoo.com> wrote:
> Cant believe I have to post this and get help... and can't believe I
> couldnt Google it reasonably well enough... I need to take a float
> variable and have it display as a string to always have two decimal
> places:
>
> 12.3333 -> 12.33
> 1.0 -> 1.00
> etc...
>
> Anyone willing to help with this one?

>>> a
12.33333
>>> print '%0.2f' % a
12.33
>>> a = 1
>>> print '%0.2f' % a
1.00


>
> thanks,
>
> Harlin





More information about the Python-list mailing list