You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
In str.format "{0:#.5g}" for decimal.Decimal doesn't print trailing zeros #58046
The '#' option:
"For floats, complex and Decimal the alternate form causes the result of the conversion to always contain a decimal-point character, even if no digits follow it. Normally, a decimal-point character appears in the result of these conversions only if a digit follows it. In addition, for 'g' and 'G' conversions, trailing zeros are not removed from the result."
IMO, the behaviour is fine; it's the docs that are unclear. The rules for Decimal are different mainly because trailing zeros have meaning for the Decimal type. (Decimal('1.250') and Decimal('1.25') are two distinct Decimal objects, unlike float('1.250') and float('1.25').)
Ah no, I take it back. I think (2) is fine---this is the usual preservation of trailing zeros where possible. (1) needs to be fixed (and issue bpo-7094 was left open waiting for this fix).
Activity
py-user commentedon Jan 22, 2012
http://docs.python.org/py3k/library/string.html#format-specification-mini-language
The '#' option:
"For floats, complex and Decimal the alternate form causes the result of the conversion to always contain a decimal-point character, even if no digits follow it. Normally, a decimal-point character appears in the result of these conversions only if a digit follows it. In addition, for 'g' and 'G' conversions, trailing zeros are not removed from the result."
no zeros with "#"
zeros without "#"
ericvsmith commentedon Jan 22, 2012
See issue bpo-7098 for a discussion.
I propose to close this issue.
py-user commentedon Jan 22, 2012
my question is about the "#" option
it is described as working with Decimal but it doesn't work with Decimal
mdickinson commentedon Jan 23, 2012
IMO, the behaviour is fine; it's the docs that are unclear. The rules for Decimal are different mainly because trailing zeros have meaning for the Decimal type. (Decimal('1.250') and Decimal('1.25') are two distinct Decimal objects, unlike float('1.250') and float('1.25').)
See also issue bpo-7094.
mdickinson commentedon Jan 23, 2012
Ah no, I take it back. I think (2) is fine---this is the usual preservation of trailing zeros where possible. (1) needs to be fixed (and issue bpo-7094 was left open waiting for this fix).