[Zope] Going CRAZY from division

Dylan Reinhardt zope@dylanreinhardt.com
Tue, 19 Nov 2002 17:26:10 -0800


Try your code at a Python interactive prompt.  You might be surprised what 
you get.

Compare:

 >>> 3*100/356
0

 >>> 3*100.0/356
0.84269662921348309

The use of all integers vs. integers and a float really does make a difference.

HTH,

Dylan

At 04:52 PM 11/19/2002, you wrote:
>Hi,
>
>--On Montag, 18. November 2002 17:17 -0500 BZ <bz@bwanazulia.com> wrote:
>
>>I have two integers "clicks" and "views" and am trying to find what the
>>ratio of clicks to views. This should be (and is on my calculator)
>>
>>clicks / views * 100   (to get the percent)
>>3 / 356 * 100 = .842 %
>This one is basic numeric. Not that python (like many other languages)
>uses integer operation if only integers are used. In this case you
>want to change your term into
>
>3*100/356
>
>First multiplication and then division. This increases exactness.
>(This is true for every fixed point arithmetik)
>
>Regards
>Tino
>
>_______________________________________________
>Zope maillist  -  Zope@zope.org
>http://lists.zope.org/mailman/listinfo/zope
>**   No cross posts or HTML encoding!  **
>(Related lists - http://lists.zope.org/mailman/listinfo/zope-announce
>http://lists.zope.org/mailman/listinfo/zope-dev )