PEP proposal for round(x,n) enhancement

Ignacio Vazquez-Abrams ignacio at openservices.net
Mon Sep 10 17:56:15 EDT 2001


On Mon, 10 Sep 2001, Christopher Smith wrote:

> I would like to see an additional syntax added to the round function.
>
> At present the syntax for round is round(x,n) where n can be a float or
> integer, (positive or negative) that indicates the digit to which the
> number x should be rounded as measured from the one's digit:
> round(12345,-2) returns 12300 while round(1.2345,2) returns 1.23.
>
> 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 about a new function instead: sigfig(x, n). That way we don't end up
overloading round() too much.

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>







More information about the Python-list mailing list