[issue13838] In str.format "{0:#.5g}" for decimal.Decimal doesn't print trailing zeros
py.user
report at bugs.python.org
Sun Jan 22 23:25:30 CET 2012
New submission from py.user <port139 at yandex.ru>:
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."
1)
>>> import decimal
>>> '{0:#.5g}'.format(1.5)
'1.5000'
>>> '{0:.5f}'.format(decimal.Decimal(1.5))
'1.50000'
>>> '{0:.5g}'.format(decimal.Decimal(1.5))
'1.5'
>>> '{0:#.5g}'.format(decimal.Decimal(1.5))
'1.5'
>>>
no zeros with "#"
2)
>>> import decimal
>>> '{0:#.5g}'.format(decimal.Decimal('1.500000000000'))
'1.5000'
>>> '{0:.5g}'.format(decimal.Decimal('1.500000000000'))
'1.5000'
>>>
zeros without "#"
----------
components: Interpreter Core, Library (Lib)
messages: 151790
nosy: py.user
priority: normal
severity: normal
status: open
title: In str.format "{0:#.5g}" for decimal.Decimal doesn't print trailing zeros
type: behavior
versions: Python 3.2
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13838>
_______________________________________
More information about the Python-bugs-list
mailing list