[FRPythoneers] Data type conversion

jafo at tummy.com jafo at tummy.com
Wed May 2 10:49:21 MDT 2001


On Wed, May 02, 2001 at 10:42:03AM -0600, J. Wayde Allen wrote:
>This kind of works, but I can't seem to get the %02f format for the
>seconds to keep the zero padding and the fractional part of the seconds at
>the same time.  

Well, the size *INCLUDES* the decimal:

   >>> f = 1.234
   >>> print '%02f' % f 
   1.234000
   >>> print '%02.1f' % f
   1.2
   >>> print '%002.1f' % f
   1.2
   >>> print '%2.1f' % f
   1.2
   >>> print '%5.1f' % f
     1.2
   >>> print '%05.1f' % f
   001.2

So, pick a precision you can live with, and 3 to it, and use that with
"%0N.<precision>f".

Sean
-- 
 "If all you have is a hammer, every problem tends to look like a nail."
Sean Reifschneider, Inimitably Superfluous <jafo at tummy.com>
tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python



More information about the FRPythoneers mailing list