Rounding up to the nearest exact logarithmic decade

Grant Edwards grante at visi.com
Tue Feb 28 18:11:08 EST 2006


On 2006-02-28, jao at geophile.com <jao at geophile.com> wrote:
> 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))))

Interesting approach.  You're converting to string at the same
time.  I would guess the OP wanted a float.

-- 
Grant Edwards                   grante             Yow!  It's OKAY -- I'm an
                                  at               INTELLECTUAL, too.
                               visi.com            



More information about the Python-list mailing list