locale.format without trailing zeros

Peter Otten __peter__ at web.de
Mon Aug 22 09:01:51 EDT 2011


przemolicc at poczta.fm wrote:

> How about this format:
> ',1'
> (the local zero is also not printed)
> 
> (I know this is strange but I need compatibility with local requirements)

I believe you have to do it yourself:

>>> locale.format("%f", 0.123)
'0,123000'
>>> locale.format("%f", 0.123).strip("0")
',123'




More information about the Python-list mailing list