Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
12 changes: 6 additions & 6 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1297,22 +1297,22 @@ 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 ``number``, ``round`` delegates to

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than lose information with this edit, I would prefer to make it more precise, "For a general Python object, round(number) or round(number, None) delegates to number.__round__(), and round(number, ndigits) delegates to number.__round__(ndigits)."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've modified the text accordingly.

``number.__round__``.

.. 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