Floating Number format problem

kelvin.you at gmail.com kelvin.you at gmail.com
Tue Jun 12 10:46:25 CEST 2007


On 6 12 ,   3 16 , ici <iltch... at gmail.com> wrote:
> On Jun 12, 10:10 am,                 <kelvin.... at gmail.com> wrote:
>
>
>
> > How could I format the float number like this: (keep 2 digit
> > precision)
> > 1.002 => 1
> > 1.12  => 1.12
> > 1.00  => 1
> > 1.567 => 1.57
> > 2324.012 => 2324.01
>
> > I can not find any Formatting Operations is able to meet my
> > requirement.
> > Any suggestion will be appreciated.
> >>> print "%.02f" % (2324.012)
> 2324.01
>
> http://docs.python.org/tut/node9.html#SECTION009100000000000000000

thank you !
But in these case:

>>> print '%.02f'%1.002
1.00
>>> print '%.02f'%1.00
1.00

I just expect it to output "1" , but these way will output 1.00




More information about the Python-list mailing list