This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2009年10月10日 18:22 by mark.dickinson, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| issue7098.patch | mark.dickinson, 2009年10月10日 19:14 | review | ||
| Messages (6) | |||
|---|---|---|---|
| msg93835 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2009年10月10日 18:22 | |
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.)
|
|||
| msg93839 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2009年10月10日 19:14 | |
Here's a patch for trunk. |
|||
| msg93840 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2009年10月10日 19:28 | |
> It should strip all trailing zeros from the result: Hmm. Thinking about this some more, I don't think this is true: format() shouldn't be throwing away significant information (in Decimal the number of trailing zeros *is* significant information) unless that's necessary to fit the result into the given precision. So I think the current code is correct. However, we could do with documenting the precise rules being used for Decimal formatting somewhere. |
|||
| msg150235 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2011年12月24日 19:54 | |
I would like to think about this one for a bit before it moves forward. |
|||
| msg150629 - (view) | Author: Stefan Krah (skrah) * (Python committer) | Date: 2012年01月04日 18:35 | |
[Mark] > So I think the current code is correct. I agree with this. Currently the 'g' format is like to_sci_string() with the added possibility of adjusting the number of significant digits. It's probably hard to come up with a better way to handle this for Decimal. |
|||
| msg174025 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2012年10月28日 10:29 | |
Closing as invalid. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:53 | admin | set | github: 51347 |
| 2012年10月28日 10:29:59 | mark.dickinson | set | status: open -> closed resolution: not a bug messages: + msg174025 |
| 2012年01月22日 23:37:31 | py.user | set | nosy:
+ py.user |
| 2012年01月04日 18:35:15 | skrah | set | nosy:
+ skrah messages: + msg150629 |
| 2011年12月24日 19:54:47 | rhettinger | set | nosy:
+ rhettinger messages: + msg150235 |
| 2011年12月24日 19:22:24 | ezio.melotti | set | versions: + Python 3.3, - Python 2.6, Python 3.1 |
| 2009年11月28日 15:19:58 | mark.dickinson | set | priority: normal -> low components: + Documentation, - Library (Lib) stage: patch review -> needs patch |
| 2009年10月10日 19:28:51 | mark.dickinson | set | messages: + msg93840 |
| 2009年10月10日 19:14:48 | mark.dickinson | set | files:
+ issue7098.patch nosy: + eric.smith messages: + msg93839 keywords: + patch stage: test needed -> patch review |
| 2009年10月10日 18:22:10 | mark.dickinson | create | |