PEP proposal for round(x,n) enhancement

Christopher Smith csmith at blakeschool.org
Wed Sep 12 15:54:44 EDT 2001


Whoops...I had a working version in mylibs and the original in a Round.py
file--which had an error in it.  The corrected def that simulates the
proposal is:

####
from math import floor,log10
def Round(x,n=0):
	if n%1:
		d=int(10*n)
		return round(x,d-1-floor(log10(abs(x))))
	else:
		return round(x,n)

print Round(1.23456,2) #returns 1.23
print Round(1.23456,0.2) #returns 1.2
####

/c





More information about the Python-list mailing list