Skip to content

bpo-30940: specify what happens if ndigits is None or omitted #3256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1297,22 +1297,23 @@ are always available. They are listed here in alphabetical order.
arguments starting at ``0``).


.. function:: round(number[, ndigits])
.. function:: round(number, ndigits=None)

Return *number* rounded to *ndigits* precision after the decimal
point. If *ndigits* is omitted or is ``None``, it returns the
point. If *ndigits* is omitted or ``None``, it returns the
nearest integer to its input.

For the built-in types supporting :func:`round`, values are rounded to the
closest multiple of 10 to the power minus *ndigits*; if two multiples are
equally close, rounding is done toward the even choice (so, for example,
both ``round(0.5)`` and ``round(-0.5)`` are ``0``, and ``round(1.5)`` is
``2``). Any integer value is valid for *ndigits* (positive, zero, or
negative). The return value is an integer if called with one argument,
otherwise of the same type as *number*.
negative). The return value is an integer if *ndigits* is omitted or is ``None``.
Otherwise the return value has the same type as *number*.

For a general Python object ``number``, ``round(number, ndigits)`` delegates to
``number.__round__(ndigits)``.
For a general Python object, ``round(number)`` or ``round(number, None)``
delegates to ``number.__round__()``, and ``round(number, ndigits)`` delegates
to ``number.__round__(ndigits)``.

.. note::

Expand Down
4 changes: 2 additions & 2 deletions Python/bltinmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2087,10 +2087,10 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds)
}

PyDoc_STRVAR(round_doc,
"round(number[, ndigits]) -> number\n\
"round(number, ndigits=None) -> number\n\
\n\
Round a number to a given precision in decimal digits (default 0 digits).\n\
This returns an int when called with one argument, otherwise the\n\
This returns an int when ndigits is omitted or is None, otherwise the\n\
same type as the number. ndigits may be negative.");


Expand Down