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.%02i" % divmod(348,100)


I dunno.  Maybe its overkill.

-- Joe

On Thursday, November 29, 2012 1:17:54 AM UTC-8, Niphlod wrote:
>
> 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 29, 2012 5:16:53 AM UTC+1, Relsi Hur wrote:
>>
>> Hello all!
>>
>> I need transform a string in a decimal number, I can to do it that way:
>>
>> >>> a = list("348")
>> >>> a.insert(-2, '.')
>> >>> "".join(a)
>> '3.48'
>> >>> 
>>
>> But when try this in web2py I get a "None" value, in the a.insert() 
>> operation.
>>
>> So, someone would know how to do this in web2py? This way or otherwise?
>>
>

-- 



Reply via email to