Rounding up to the nearest exact logarithmic decade

jao at geophile.com jao at geophile.com
Tue Feb 28 17:47:59 EST 2006


Quoting Derek Basch <dbasch at yahoo.com>:

> Given a value (x) that is within the range (1e-1, 1e7) how do I round
> (x) up to the closest exact logarithmic decade? For instance:

How about this:

def roundup(x):
    if x < 1:
        return 1
    else:
        return '1' + ('0' * len(str(int(x))))

Jack Orenstein





More information about the Python-list mailing list