[Python-Dev] FixedPoint and % specifiers.

David LeBlanc whisper@oz.net
Wed, 5 Feb 2003 17:22:51 -0800


Let me be the first to state, most emphatically, that I'm not about to
change anything, ESPECIALLY the Python core! Besides, I don't have check-in
priviledges AFAIK and burgling Tim's pockets for the keys would probably
yield only pickles ;)

still-nibblingly-yours

David LeBlanc
Seattle, WA USA

> -----Original Message-----
> From: guido@python.org [mailto:guido@python.org]
> Sent: Wednesday, February 05, 2003 17:01
> To: David LeBlanc
> Cc: python-dev@python.org
> Subject: Re: [Python-Dev] FixedPoint and % specifiers.
>
>
> > Displaying FixedPoints:
> >
> > Python 2.2.1 (#34, Jul 16 2002, 16:25:42) [MSC 32 bit (Intel)] on win32
> > Type "help", "copyright", "credits" or "license" for more information.
> > Alternative ReadLine 1.5 -- Copyright 2001, Chris Gonnerman
> > >>> from fixedpoint import *
> > >>> a = FixedPoint(2.135)
> > >>> print '%d' % (a)
> > 2
> > >>> print '%4d' % (a)
> >    2
> > >>> print '%e' % (a)
> > 2.130000e+000
> > >>> print '%f' % (a)
> > 2.130000
> > >>> print '%2f' % (a)
> > 2.130000
> > >>> print '%.2d' % (a)
> > 02
> > >>> print '%s' % (a)
> > 2.13
> > >>> a.set_precision(4)
> > >>> print '%s' % (a)
> > 2.1300
> >
> > I naively expected the %d to produce 2.315
>
> Eh?  In C as well as Python, %d means decimal *integer*.  The format
> specifier to use fixed point notation is %f.
>
> Please don't change this!
>
> --Guido van Rossum (home page: http://www.python.org/~guido/)