[issue6871] decimal.py: more format issues

Stefan Krah report at bugs.python.org
Wed Sep 9 23:06:26 CEST 2009


Stefan Krah <stefan-usenet at bytereef.org> added the comment:

Issue 1:

I would definitely keep the spelling in decimal, my concern was only the
padding.

The C standard agrees with Mark's view:

"Leading zeros (following any indication of sign or base) are used to
pad to the field width rather than performing space padding, except when
converting an infinity or NaN."

If this could be agreed on, issue 1 should be handled by changing float
and decimal 2.6.


Issue 2:

I can't find it quickly in the C standard, but gcc warns in this situation:

   warning: repeated '0' flag in format

This would support the behavior of decimal and float should be changed.


I would like to add two new issues.

Issue 3:

Regarding padding, the C standard further says:

"If the 0 and - flags both appear, the 0 flag is ignored"

This is quite sensible, since signless 0 padding looks a bit awkward.
(But this is a minor issue). 


Issue 4:

>>> format(Decimal('1e88'), '0<20')
'1E+88000000000000000'

>>> format(float('1e88'), '0<20')
'0000000000000001e+88'

I think right-padding with digits is dangerous, since it changes the
numerical value. I'm not sure what float does, it doesn't look correct
(but protects the user).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6871>
_______________________________________


More information about the Python-bugs-list mailing list