[Zope] expression evaluateion

Evan Simpson evan@4-am.com
Thu, 16 Mar 2000 11:29:07 -0500


----- Original Message -----
From: Chien-pin Wang <cpw@suprize.com>
>     Zope seems to evaluate expressions in an unconventional way.
> Say I have three properties, a=3, b=5, c=7 set in a Folder. In
> a DTML Document I tried to say <dtml-var "a/b*c"> and got result
> 0. The expression was evaluated as a/(b*c) and rounded off. Is
> not the expression supposed to be evaluated as (a/b)*3? The
> result is not correct still if we put it this way:
> <dtml-var "(a/b)*3">. I still got 0 as the result. Did I miss
> anything fundamentally or is this a, bug?

You've run into a misfeature of Python.  Since 'a' and 'b' are integers,
'a/b' is performed as an integer division.

Thus 'a/b*c' == '(3/5)*7' == '(0)*7' == '0'.  If you want floating point
division, you need to make 'a' or 'b' a float, either directly or by writing
'_.float(a)/b*c'.

Cheers,

Evan @ digicool & 4-am