PEP proposal for round(x,n) enhancement

Chris Barker chrishbarker at home.net
Thu Sep 13 01:11:36 CEST 2001


Markus Schaber wrote:

> And this is what I meant - the float doesn't store how many digits are
> significant, so when you round to n digits, you often get an
> approximation to the rounded number, and this way don't have any
> information about the accuracy afterwards.

OK, I get it now, but this doesn't make the proposal any more useless
than the current round. 
>>> round(0.2,3)
0.20000000000000001

Just because Python doesn't store any information about the accuaracy,
doesn't mean that the programmmer doesn't know what was done. If you
take this now stored number and display the first <17 digits, it will
display what is wanted, and if you do calculations with it, it will do
what is wanted as well (as well as FP ever can).


> My proposal only has to do with enhancing the
> > syntax used by the round() function.
> 
> And enhancing the semantics :-)

True, which is why I'd be just as happy to see it in a separate
function.

Note: the current round() will accept decimal input, even if it doesn't
do anything with it, so adding this functionality does hav ethe
potential to break someones code, somewhere:

>>> round(1.2345,2.3)
1.23
>>> round(1.2345,0.3)
1.0
>>>

-Chris

-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------



More information about the Python-list mailing list