[Tutor] Re: string format float omitting decimal point?

Andrei project5 at redrival.net
Tue Sep 16 15:42:54 EDT 2003


Jeff Kowalczyk wrote:
> Is there a way to omit a decimal point directly in float string formatting?

The point of string formatting is to show the number as it is, not to modify it.

>>>>('%0.2f' % 23.06).replace('.','')
> 
> '2306'

You can either modify the number in advance (multiply by 100 and int/round it), 
or - if all your numbers have two decimals - use the slightly shorter 
str(23.06).replace('.',''). But in the end it's all pretty much the same really.

-- 
Yours,

Andrei

=====
Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5 at bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq gur 
yvfg, fb gurer'f ab arrq gb PP.





More information about the Tutor mailing list