[Python-bugs-list] [ python-Bugs-795506 ] Wrong handling of string format code for float values.

SourceForge.net noreply at sourceforge.net
Tue Aug 26 22:57:19 EDT 2003


Bugs item #795506, was opened at 2003-08-26 12:13
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=795506&group_id=5470

Category: Python Library
>Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Fionn Behrens (fionn)
>Assigned to: Raymond Hettinger (rhettinger)
Summary: Wrong handling of string format code for float values.

Initial Comment:

According to the python2.3 library reference, section
2.2.6.2
( lib/typesseq-strings.html#l2h-205 in the html docs) a
string
can be formatted to output a "numeric value" padded
with leading zeroes or spaces. This works well with
integers, but not at all with float values.

"%02i - %02.2f" % (3, 3.1415)
SHOULD result in:  "03 - 03.14"
but DOES result in: "03 - 3.14"

In addition the table of format strings mentions a %F
format (with capitalized f) which is invalid if used.

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-08-26 23:57

Message:
Logged In: YES 
user_id=80475

You're going to hate yourself for this one ;-)  
The width field in your example allows no room for padding:

>>> "%02i - %06.2f" % (3, 3.1415)
'03 - 003.14'

The comment about the capitalized F *is* valid.
Applied fix to: 
    Objects/stringobject.c  2.210
    Objects/unicodeobject.c 2.195
    Lib/test/test_strings.py 1.33

Thanks for the report.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=795506&group_id=5470



More information about the Python-bugs-list mailing list