[New-bugs-announce] [issue7098] g formatting for decimal types should always strip trailing zeros.

Mark Dickinson report at bugs.python.org
Sat Oct 10 20:22:12 CEST 2009


New submission from Mark Dickinson <dickinsm at gmail.com>:

Type 'g' formatting for Decimal instances doesn't behave in the same way 
as for floats when an explicit precision is given.  It should strip all 
trailing zeros from the result:

Python 2.7a0 (trunk:75309, Oct 10 2009, 13:44:18) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from decimal import Decimal
>>> format(Decimal('123.00'), '.6g')  # expect '123'
'123.00'

(When no explicit precision is given, Decimal formatting with type 'g' 
tries to preserve the information about the exponent of the Decimal 
instance whenever possible;  this also differs from float formatting, but 
it's intentional.  This should probably be documented.)

----------
assignee: mark.dickinson
components: Library (Lib)
messages: 93835
nosy: mark.dickinson
priority: normal
severity: normal
stage: test needed
status: open
title: g formatting for decimal types should always strip trailing zeros.
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2

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


More information about the New-bugs-announce mailing list