Skip to content

Document (undefined) rounding behaviour of new-style formatting #99880

@jowagner

Description

@jowagner

Documentation

Current documentation of new-style formatting does not talk about rounding and that the rounding behaviour is undefined / platform-dependent. Popular platforms seem to round to the nearest number of the selected precision with ties rounded to the number with even last digit, e.g. '{:.2f}'.format(1/8) produces 0.12. This choice as well the dependence on the platform will be unexpected to many users.

While ties are rare for random numbers, ties can be frequent in some applications, e.g. when reporting a percentage where the total is a fairly small multiple (greater than 1) of a power of 10 and the number of digits selected for printing covers increments of 1 divided by that power of 10, e.g. n = 80000 and '{:.2f}%'.format(100*count/n).

The documentation should draw attention to the undefined rounding behaviour and to that there are a number of competing popular choices. A link to the list of rounding behaviours supported by the decimal module may also help.

Based on discussion in issue #99534.

Similar: issue #99875

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions