locale.format without trailing zeros

Anssi Saari as at sci.fi
Mon Aug 22 06:59:54 EDT 2011


przemolicc at poczta.fm writes:

> Hello,
>
>>>> import locale
>>>> locale.setlocale(locale.LC_ALL, "pl_PL")
> 'pl_PL'
>>>> i=0.20
>>>> j=0.25
>>>> locale.format('%f', i)
> '0,200000'
>>>> locale.format('%f', j)
> '0,250000'
>
> I need to print the numbers in the following format:
> '0,2'	(i)
> '0,25'	(j)
> So the last trailing zeros are not printed.

That would be the %g conversion specifier.



More information about the Python-list mailing list