I was so fixed in the string format, that I was ignoring the basic math!
=/
Thanks to everyone for the tips!!
This solve very well:
"%i.%02i" % divmod(348,100)
Em quinta-feira, 29 de novembro de 2012 09h12min39s UTC-2, Joe Barnhart
escreveu:
>
> Bzzzt! Thanks for playing!
>
> You get 3.0
Bzzzt! Thanks for playing!
You get 3.0 for your result. (I'm not a python genius but I keep an
interpreter handy just to type in stuff and see what I get.)
>>> round(int("348")/100,3)
3.0
In your example, you rounded the result AFTER the integer division of
348/100. But the result of
Il 29/11/12 10:49, Joe Barnhart ha scritto:
Hmmm...
That would give "3" since Python 2.x keeps the calculation as integer
(it won't coerce it to a float).
He could do a=int(a)/100.0 But that puts it into a floating point
value, and rounding sometimes gives surprising and unexpected results
Hmmm...
That would give "3" since Python 2.x keeps the calculation as integer (it
won't coerce it to a float).
He could do a=int(a)/100.0 But that puts it into a floating point value,
and rounding sometimes gives surprising and unexpected results.
I am a fan of divmod. How about:
"%i
web2py executes python code. If you can do it in the shell, you can do the
same thing in web2py. Be careful to check the variable types, probably in
your app something is a little different from your shell environment. BTW,
why don't you just
a = '348'
a = int(a) / 100
?
On Thursday, November
5 matches
Mail list logo