[Python-Dev] FixedPoint and % specifiers.

Guido van Rossum guido@python.org
Wed, 05 Feb 2003 20:00:37 -0500


> 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/)