msg235904 - (view) |
Author: Ian Kelly (ikelly) |
Date: 2015-02-13 17:15 |
>>> '{:g}'.format(D('0.000001'))
'0.000001'
Formatted with '{:e}', the exponent would be -6, so per the formatting rules described under the 'g' specifier at https://docs.python.org/3/library/string.html#format-specification-mini-language the above should be formatted using exponential notation.
|
msg235984 - (view) |
Author: Stefan Krah (skrah) * |
Date: 2015-02-14 18:53 |
For Decimal the cutoff point is -6 instead of -4 (following the
decimal specification instead of the C standard).
|
msg237025 - (view) |
Author: Ezio Melotti (ezio.melotti) * |
Date: 2015-03-02 07:46 |
Should we add a note to the format docs, or just close this?
|
msg237032 - (view) |
Author: Mark Dickinson (mark.dickinson) * |
Date: 2015-03-02 08:42 |
I don't think we should close: the documentation as written explicitly says that the rules apply to both Decimal and float: "The available presentation types for floating point and decimal values are ...". But the details listed for 'g' are incorrect. We could either fix the description for 'g' to explain what happens for `Decimal`, or state up front that the table only applies directly to the `float` type, and that `Decimal` is similar but not identical.
|
msg237438 - (view) |
Author: Tuomas Suutari (tuomas.suutari) * |
Date: 2015-03-07 11:10 |
Here's a patch that fixes the description for 'g' to explain what happens for `Decimal` and also documents the Decimal.__format__ in the documentation of the decimal module.
|
msg324473 - (view) |
Author: Lorenz Mende (LorenzMende) * |
Date: 2018-09-02 08:02 |
I want to bring this issue up again.
As the others correctly stated, either the documentation or the implementation of Decimal 'g' formatting is incorrect.
For floats the implementation suits the docu:
>>> '{:g}'.format(0.00001)
'1e-05'
For decimals:
>>> '{:g}'.format(decimal.Decimal('0.00001'))
'0.00001'
As there is a deviation between documentation and implementation, I advise to modify one of both.
|
msg335183 - (view) |
Author: Brennan D Baraban (bdbaraban) * |
Date: 2019-02-11 00:36 |
What is the status of this issue? I can submit a PR based on Tuomas Suutari's patch.
|
msg335198 - (view) |
Author: Tuomas Suutari (tuomas.suutari) * |
Date: 2019-02-11 08:12 |
> What is the status of this issue? I can submit a PR based on Tuomas Suutari's patch.
Don't know more about the status, but nobody seemed to care to take my
patch forward. If contributions are accepted as GitHub pull requests
these days, I can do it myself too.
|
msg335199 - (view) |
Author: Stefan Krah (skrah) * |
Date: 2019-02-11 08:31 |
The patch LGTM, but I'm not sure if we need to document __format__().
Personally I probably wouldn't.
|
msg335200 - (view) |
Author: Karthikeyan Singaravelan (xtreak) * |
Date: 2019-02-11 08:31 |
> If contributions are accepted as GitHub pull requests
these days, I can do it myself too.
GitHub pull requests are accepted. Please see https://devguide.python.org/ .
Thanks
|
msg335201 - (view) |
Author: Stefan Krah (skrah) * |
Date: 2019-02-11 08:34 |
Yes, these days PRs are the only way to get anything done. Before
GitHub it would have been possible to just commit the small diff
directly to master.
|
msg335251 - (view) |
Author: Brennan D Baraban (bdbaraban) * |
Date: 2019-02-11 18:44 |
Well, Tuomas, I defer submission of a PR to you, as its your original patch.
|
msg335503 - (view) |
Author: Brennan D Baraban (bdbaraban) * |
Date: 2019-02-14 07:25 |
I submitted a PR just now. I only pushed the change to `string.rst`, as per Stefan Krah's suggestion.
|
msg336470 - (view) |
Author: Stefan Krah (skrah) * |
Date: 2019-02-24 13:53 |
I just noticed that there are other differences, for example the "removal of trailing zeros" passage does not apply to Decimal:
>>> format(Decimal("1.000000e-6"), "g")
'0.000001000000'
Perhaps it would be easier to have separate docs for float and decimal after all, or a long footnote for decimal.
|
msg336471 - (view) |
Author: Stefan Krah (skrah) * |
Date: 2019-02-24 14:05 |
On the other hand, the docs say "insignificant trailing zeros are removed from the significand", so technically it *is* correct, because trailing zeros are significant in decimal.
|
msg337049 - (view) |
Author: Brennan D Baraban (bdbaraban) * |
Date: 2019-03-03 22:36 |
Hi Stefan. Is there an update you would like me to make on this PR? Otherwise, pinging for review.
|
msg351885 - (view) |
Author: Julien Palard (mdk) * |
Date: 2019-09-11 13:59 |
New changeset 1660a61a105bcd62e2dfa77885959a8992e9f14e by Julien Palard (Brennan D Baraban) in branch 'master':
bpo-23460: Fix documentation for decimal string :g formatting (GH-11850)
https://github.com/python/cpython/commit/1660a61a105bcd62e2dfa77885959a8992e9f14e
|
msg351909 - (view) |
Author: Julien Palard (mdk) * |
Date: 2019-09-11 14:38 |
New changeset 629f1f87e9b0bfd9f1dc3d02f966decde5c65201 by Julien Palard (Miss Islington (bot)) in branch '3.8':
bpo-23460: Fix documentation for decimal string :g formatting (GH-11850) (GH-15954)
https://github.com/python/cpython/commit/629f1f87e9b0bfd9f1dc3d02f966decde5c65201
|
|
Date |
User |
Action |
Args |
2022-04-11 14:58:12 | admin | set | github: 67648 |
2019-09-11 14:38:47 | mdk | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
2019-09-11 14:38:28 | mdk | set | messages:
+ msg351909 |
2019-09-11 13:59:48 | miss-islington | set | pull_requests:
+ pull_request15589 |
2019-09-11 13:59:40 | mdk | set | nosy:
+ mdk messages:
+ msg351885
|
2019-03-03 22:36:45 | bdbaraban | set | messages:
+ msg337049 |
2019-02-24 14:05:33 | skrah | set | messages:
+ msg336471 |
2019-02-24 13:53:55 | skrah | set | messages:
+ msg336470 |
2019-02-14 07:25:15 | bdbaraban | set | messages:
+ msg335503 |
2019-02-14 07:05:30 | bdbaraban | set | stage: needs patch -> patch review pull_requests:
+ pull_request11881 |
2019-02-11 18:44:41 | bdbaraban | set | messages:
+ msg335251 |
2019-02-11 08:34:10 | skrah | set | messages:
+ msg335201 |
2019-02-11 08:31:34 | xtreak | set | nosy:
+ xtreak messages:
+ msg335200
|
2019-02-11 08:31:21 | skrah | set | messages:
+ msg335199 |
2019-02-11 08:12:22 | tuomas.suutari | set | messages:
+ msg335198 |
2019-02-11 00:36:42 | bdbaraban | set | nosy:
+ bdbaraban messages:
+ msg335183
|
2018-10-24 20:05:10 | sir-sigurd | set | nosy:
+ sir-sigurd
|
2018-09-02 08:02:24 | LorenzMende | set | nosy:
+ LorenzMende messages:
+ msg324473
|
2015-03-07 11:10:51 | tuomas.suutari | set | files:
+ issue23460.patch
nosy:
+ tuomas.suutari messages:
+ msg237438
keywords:
+ patch |
2015-03-02 09:12:24 | ezio.melotti | set | keywords:
+ easy stage: needs patch type: enhancement versions:
+ Python 2.7, Python 3.5 |
2015-03-02 08:42:44 | mark.dickinson | set | messages:
+ msg237032 |
2015-03-02 07:46:41 | ezio.melotti | set | nosy:
+ mark.dickinson, ezio.melotti messages:
+ msg237025
|
2015-02-14 18:53:37 | skrah | set | nosy:
+ docs@python, skrah messages:
+ msg235984
assignee: docs@python components:
+ Documentation, - Library (Lib) type: behavior -> (no value) |
2015-02-13 17:15:21 | ikelly | create | |