Number format...

Justin Shaw wyojustin at hotmail.com
Sat Jan 4 20:43:49 EST 2003


"Afanasiy" <abelikov72 at hotmail.com> wrote in message
news:a33f1vskqkol38pmcre2lusk1u0j4f2obc at 4ax.com...
> On Sun, 05 Jan 2003 01:21:09 GMT, Afanasiy <abelikov72 at hotmail.com>
> wrote:
>
> >What do I need to do to convert .1352345 to '0.14' ?
> >
> >>>> repr(round(.1352345,2))
> >'0.14000000000000001'
>
> I found the answer...
>
>   str(round(0.1352345,2)) == '0.14'
>
> But have another question...
>
>   str(round(0.1001,2)) == '0.1'
>
> How do I pad with a zero now? ('0.10')

How about this?
>>> print '%.2f' % .1352345
0.14
>>> print '%.2f' % .1
0.10
>>>






More information about the Python-list mailing list