[EMAIL PROTECTED] wrote:
> BTW, are the python-dev guys aware that 10 ** -1 = 0.10001 ?
http://docs.python.org/tut/node16.html
--
http://mail.python.org/mailman/listinfo/python-list
On 2006-02-28, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I like Fredrik's solution. If for some reason you are afraid of
> logarithms, you could also do:
>
x = 4978
decades = [10 ** n for n in xrange(-1,8)]
import itertools
itertools.ifilter(lambda decade: x < decade, deca
I like Fredrik's solution. If for some reason you are afraid of
logarithms, you could also do:
>>> x = 4978
>>> decades = [10 ** n for n in xrange(-1,8)]
>>> import itertools
>>> itertools.ifilter(lambda decade: x < decade, decades).next()
1
BTW, are the python-dev guys aware that 10 ** -1 =
On 2006-02-28, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Quoting Derek Basch <[EMAIL PROTECTED]>:
>
>> 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:
Thanks effbot. I knew their had to be something buried in the math
module that could help. ceil() it is!
--
http://mail.python.org/mailman/listinfo/python-list
Em Ter, 2006-02-28 às 17:47 -0500, [EMAIL PROTECTED] escreveu:
> Quoting Derek Basch <[EMAIL PROTECTED]>:
>
> > 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
Quoting Derek Basch <[EMAIL PROTECTED]>:
> 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
Derek Basch wrote:
> 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:
>
> 10**3 = 1000
> x = 4978
> 10**4 = 1
> x = 1
how about
>>> import math
>>> def roundup(x):
...return 10**math.ceil
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:
10**3 = 1000
x = 4978
10**4 = 1
x = 1
Thanks Everyone!
Derek Basch
--
http://mail.python.org/mailman/listinfo/python-list