[Tutor] floats

Christian Witts cwitts at compuscan.co.za
Tue Jun 7 07:15:59 CEST 2011


On 2011/06/07 04:43 AM, Michael bridges wrote:
> i saw it somewhere, but where?
>
> i want to 10 / 1000 and get 0.01 not 0
> if 1000 is made 1000.00 then 0.01 is printed
> but that gives 500 / 1000.00 is 0.5 not 0.50
>
> i might be thinking C# not python.
>
> can someone till me how to get a two decimal precision every time?
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

 >>> 100/1000
0
 >>> from __future__ import division
 >>> 100/1000
0.1
 >>> 100//1000
0

So you can still get the old behaving floor division using double 
divisors and any normal syntax will be true division. In Python 3.x it's 
already the standard, this is only necessary for Python 2.x

-- 

Christian Witts

//

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110607/aaf20a1b/attachment.html>


More information about the Tutor mailing list