Hi, 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? Chien-pin
Chien-pin Wang wrote:
Hi,
Zope seems to evaluate expressions in an unconventional way.
Zope doesn't do anything above and beyond what python does.
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?
Python rounds integers, quite simply: Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
1/2 0 3/5*7 0 (3/5)*7 0 3/(5*7) 0
integers as input gives an integer as output. Obviously there are two schools of thought on this. If you want a floating point number, use 'float()' (or in DTML, _.float())
float(1)/float(2) 0.5
-Michel
Chien Try this <dtml-var "_.float(a)/_.float(b)*_.float(c)"> You calculation is using integers and there is no automatic conversion being done. You need to explicitly tell zope that you want float calculations. HTH Phil phil.harris@zope.co.uk ----- Original Message ----- From: "Chien-pin Wang" <cpw@suprize.com> To: <zope@zope.org> Sent: Thursday, March 16, 2000 5:57 AM Subject: [Zope] expression evaluateion
Hi,
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?
Chien-pin
_______________________________________________ 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 )
Chien-pin Wang schrieb:
Hi,
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 have to convert it from integer to float. Try: <dtml-var "(_.float(a)/b)*c"> Though you're rigth, you need the parenthesis for the correct evaluation. hth, Thomas
----- Original Message ----- From: "Chien-pin Wang" <cpw@suprize.com> To: <zope@zope.org> Sent: Thursday, March 16, 2000 12:57 AM Subject: [Zope] expression evaluateion
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.
Your properties look like integers, and I believe that is your problem. Try this: <dtml-var "_.float(a)/b*c"> By converting a to a float and then doing the rest of the expression, python should consider the whole expression to be floating point. Kevin
----- 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
Hi Chien, Chien-pin Wang wrote:
Hi,
Zope seems to evaluate expressions in an unconventional way.
No, its all alright ;)
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?
No, its integer :) 3/5 is 0, anything multiplicated with 0 will be 0. so 3/5*7 is 0 no matter where you set brackets :) Integer does not round, it only cuts off everything after the "." Eventually you want: a=3.0, b=5.0 and c=7.0 (even only one variable beeing "float" wuld be sufficient) Hth Tino Wildenhain
participants (7)
-
Chien-pin Wang -
Evan Simpson -
Kevin Dangoor -
Michel Pelletier -
Phil Harris -
Thomas Weiner -
Tino Wildenhain