msg288710 - (view) |
Author: (ChrisRands) * |
Date: 2017-02-28 12:30 |
With a negative integer for ndigits the output from 'round()', for example 'round(3, -2)', is always zero ('0' for 'int.__round__' and '0.0' or '-0.0' for 'float.__round__'). I think either it should raise an exception or the docs should be updated to reflect the current behavior. The docs are currently silent on this: https://docs.python.org/3/library/functions.html#round I don't know C, but there appears to be a note in the source about this implying it is the desired behavior but without an explanation: "For ndigits < NDIGITS_MIN, x always rounds to +-0.0.": https://github.com/python/cpython/blob/6f0eb93183519024cb360162bdd81b9faec97ba6/Objects/floatobject.c Anyway, I can't imagine an actual use case for negative ndigits. |
|
|
msg288711 - (view) |
Author: Gerrit Holl (Gerrit.Holl) * |
Date: 2017-02-28 12:34 |
>>> round(21345, -2) 21300 Desired and useful to me. |
|
|
msg288713 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
Date: 2017-02-28 12:38 |
Yep, it's (genuinely) a feature, not a bug, and being able to round to the nearest ten, hundred, thousand, etc. is useful. The docs could perhaps be improved to make it clearer that this is supported. |
|
|
msg288714 - (view) |
Author: (ChrisRands) * |
Date: 2017-02-28 12:45 |
Ah yes, you're both completely right of course. Perhaps the docs could still be clarified though. I managed to completely overlook this, and perhaps other non-expert Python users would too. |
|
|
msg288715 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
Date: 2017-02-28 12:50 |
Yes, I think the initial description could be clarified. It currently reads: > Return the floating point value number rounded to ndigits digits after the decimal point. ... which doesn't make it clear what happens for negative ndigits. There's a line in the second paragraph: > values are rounded to the closest multiple of 10 to the power minus ndigits which technically *does* cover the case of negative ndigits correctly, but I think it would be good to have a clarification in the first paragraph of the description. |
|
|
msg288751 - (view) |
Author: Vedran Čačić (veky) * |
Date: 2017-03-01 09:38 |
This is one of those things that show Python being extremely consistent within itself. Of course, docs should be clarified if needed, but the feature is desirable and useful. |
|
|
msg290644 - (view) |
Author: Cheryl Sabella (cheryl.sabella) *  |
Date: 2017-03-27 20:54 |
I'm new to contributing. Can I work on this one? |
|
|
msg290662 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2017-03-27 22:15 |
New changeset 6003db7db5fec545c01923c198a5fdfca5a91538 by Victor Stinner (Gerrit Holl) in branch 'master': bpo-29677: DOC: clarify documentation for `round` (#357) https://github.com/python/cpython/commit/6003db7db5fec545c01923c198a5fdfca5a91538 |
|
|
msg290669 - (view) |
Author: Mariatta (Mariatta) *  |
Date: 2017-03-28 00:02 |
New changeset 596506216104613591218c2896cdb49fa0b7e5bb by Mariatta in branch '3.6': bpo-29677: DOC: clarify documentation for `round` (GH-357) (GH-862) https://github.com/python/cpython/commit/596506216104613591218c2896cdb49fa0b7e5bb |
|
|
msg290670 - (view) |
Author: Mariatta (Mariatta) *  |
Date: 2017-03-28 00:09 |
New changeset 8994f36287b068e8ea9a9230fc90eda72bf5fff0 by Mariatta in branch '3.5': bpo-29677: DOC: clarify documentation for `round` (GH-357) (GH-863) https://github.com/python/cpython/commit/8994f36287b068e8ea9a9230fc90eda72bf5fff0 |
|
|
msg290671 - (view) |
Author: Mariatta (Mariatta) *  |
Date: 2017-03-28 00:19 |
Cheryl, thank you for your interest in working on this issue. The original issue has been addressed in Gerrit Holl's PR. But it seems like the docs can be further improved. Here is Victor's comment about it: (copied from GH-357) ``` while we are modifying the doc, I dislike the start: "Return the floating point value number": number can be an integer. round(123, -2) doesn't use floating point numbers. Maybe rephrase to following text? Return number rounded to (...). number can be an integer or a floating point number. Or just remove "floating pointer number"? ``` Will you be interested in preparing a PR to address Victor's comment above? Thanks :) |
|
|
msg290672 - (view) |
Author: Mariatta (Mariatta) *  |
Date: 2017-03-28 00:22 |
GH-357 is: https://github.com/python/cpython/pull/357/files :) |
|
|
msg290694 - (view) |
Author: Cheryl Sabella (cheryl.sabella) *  |
Date: 2017-03-28 10:13 |
Mariatta, Yes, thank you, I will work on a pull request to address Victor's comment. Since it's my first time, I hope to read through the contributing docs and get this done today or tomorrow. Thank you! |
|
|
msg290793 - (view) |
Author: Mariatta (Mariatta) *  |
Date: 2017-03-29 21:14 |
New changeset 85deefcf61d3cc192846f41a4ccc6df17da60c98 by Mariatta (csabella) in branch 'master': bpo-29677: DOC: clarify documentation for `round` (GH-877) https://github.com/python/cpython/commit/85deefcf61d3cc192846f41a4ccc6df17da60c98 |
|
|
msg290794 - (view) |
Author: Cheryl Sabella (cheryl.sabella) *  |
Date: 2017-03-29 22:29 |
Mariatta, Thank you so much for your support and encouragement while I worked on my first PR. You've made this an awesome experience! |
|
|
msg290802 - (view) |
Author: Mariatta (Mariatta) *  |
Date: 2017-03-30 02:10 |
New changeset 2609c9ee78c53d501914a5a90dbe094d9a8c3c97 by Mariatta in branch '3.6': bpo-29677: DOC: clarify documentation for `round` (GH-877) (GH-892) https://github.com/python/cpython/commit/2609c9ee78c53d501914a5a90dbe094d9a8c3c97 |
|
|
msg290803 - (view) |
Author: Mariatta (Mariatta) *  |
Date: 2017-03-30 02:10 |
New changeset eef6e11f9883f54de491121b8c49fdadd3e3506d by Mariatta in branch '3.5': bpo-29677: DOC: clarify documentation for `round` (GH-877) (GH-893) https://github.com/python/cpython/commit/eef6e11f9883f54de491121b8c49fdadd3e3506d |
|
|
msg290804 - (view) |
Author: Mariatta (Mariatta) *  |
Date: 2017-03-30 02:16 |
Gerrit, Cheryl, thanks and congrats for your first contributions to CPython! They've been merged and backported to 3.5 and 3.6. So I'm closing this now. Thanks all :) |
|
|