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 the integer division was 3, so your rounded 
version is 3.0.

On Thursday, November 29, 2012 2:02:29 AM UTC-8, Manuele wrote:
>
>  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.
>
> my 2 cent...
>
> a = round(int(a)/100, 3)
>
>     M.
>  

-- 



Reply via email to