PEP proposal for round(x,n) enhancement

Russell E. Owen owen at astrono.junkwashington.emu
Mon Sep 17 15:26:05 EDT 2001


>...The enhancement that I would like to see is the ability to indicate the 
>number of digits counting *from the 1st non-zero digit* that should be 
>reported.  These digits are often called the significant digits.  Both 
>12345 and 1.2345 when rounded to the 3rd significant digit are 12300 
>and 1.23 but instead of having to inspect the numbers to figure out 
>what digit to round them to, an argument that would be interpreted as 
>"the 3rd digit counting from the first non-zero digit" would do the job 
>instead.
>
>***
>How to add this syntax to the round function:
>
>
>round(x,n) will test to see if there is a decimal portion to n.  If 
>there is, n will be multiplied by 10 and the integer of the resulting 
>value will be the number of digits to which x will be rounded.

I like the idea of having this functionality, but I find the proposed 
user interface too subtle and confusing. I suggest one of the following 
implementations, either of which would be much clearer:
- add an optional keyword argument to round to obtain the other behavior
- create a new function (possibly in the math library) to produce this 
behavior

This brings up a more general point. Keyword arguments seem rather 
underutilized in the libraries. For instance we have various functions 
that combine lists. Some of them stop at the end of the shortest list. 
Others go on to the end of the longest list. Why this inconsistency? 
Presumably both behaviors are useful, and an optional keyword argument 
for each function would permit either behavior as desired.

-- Russell



More information about the Python-list mailing list