-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Description
Documentation
Current documentation of printf-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' %(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%%' %(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.