[FRPythoneers] Data type conversion

J. Wayde Allen wallen at its.bldrdoc.gov
Wed May 2 11:02:47 MDT 2001


On Wed, 2 May 2001 jafo at tummy.com wrote:

> 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".

Very cool - that works like a charm!  This has been something that has
always confused me with % format strings.

- Wayde
  (wallen at its.bldrdoc.gov)




More information about the FRPythoneers mailing list