[issue39077] Numeric formatting inconsistent between int, float and Decimal

Michael Amrhein report at bugs.python.org
Tue Dec 17 16:06:49 EST 2019


Michael Amrhein <michael at adrhinum.de> added the comment:

Mark, I mostly agree with your classifications / proposals.
Regarding cases 3-7 I'd like to suggest a slightly different resolution:
Following my interpretation of the spec ("use zeropad *only* if no align is given"), "<020", ">020", "^020" and "=020" would be treated equivalent to "<20", ">20", "^20" and "=20":

format(12345, "<020") -> '-12345              ', not '-1234500000000000000'
format(12345, ">020") -> '              -12345', not '00000000000000-12345'
format(12345, "^020") -> '       -12345       ', not '0000000-123450000000'
format(12345, "=020") -> '-              12345', not '-0000000000000012345'

For '<', '>' and '^' I can't imagine any code depending on the current behaviour of int and float, so this change is unlikely to break anything. 
For '=' it might be reasonable to make an exception (and state it in the doc), so that "020", "=020", "0=020" and "0=20" are treated as equivalent.
For Decimal this would mean to loosen the behaviour, as you proposed.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39077>
_______________________________________


More information about the Python-bugs-list mailing list