Re: [Zope] dtml decimals

2000-12-14 Thread Tres Seaver

Andy McKay [EMAIL PROTECTED] wrote:
 
 dtml-var "3/2" fmt="%.2d" instead of getting 1.50 as I was expecting I get
 1.00, I never seem to be getting decimals. Whats the obivous thing Im
 missing here?

Note the following::

 $ python
 Python 1.5.2 (#1, Feb  1 2000, 16:32:16)  [GCC egcs-2.91.66 1...
 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
  3/2
 1
  3.0/2
 1.5

Python performs integer division when handed integer arguments;
you need::

  dtml-var "3.0/2" fmt="%.2d"

  dtml-var "_.float( x )/2" fmt="%.2d"

or equivalent.

Tres.
--
===
Tres Seaver[EMAIL PROTECTED]
Digital Creations "Zope Dealers"   http://www.zope.org

___
Zope maillist  -  [EMAIL PROTECTED]
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 )




Re: [Zope] dtml decimals

2000-12-13 Thread Andy McKay

Well for one thing that example should be dtml-var "3/2" fmt="%.2f"
--
  Andy McKay, Developer.
  ActiveState.

- Original Message -
From: "Andy McKay" [EMAIL PROTECTED]
To: "zope-misc" [EMAIL PROTECTED]
Sent: Wednesday, December 13, 2000 10:03 AM
Subject: [Zope] dtml decimals


 dtml-var "3/2" fmt="%.2d" instead of getting 1.50 as I was expecting I
get
 1.00, I never seem to be getting decimals. Whats the obivous thing Im
 missing here?

 Cheers.

 --
   Andy McKay, Developer.
   ActiveState.


 ___
 Zope maillist  -  [EMAIL PROTECTED]
 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 )



___
Zope maillist  -  [EMAIL PROTECTED]
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 )




Re: [Zope] dtml decimals

2000-12-13 Thread Andy McKay

Yup, the implication there is that I am doing a 3/2, im not, that was an
example. Im using variables and hence its easiest to cast one of them as a
float is easier than adding .0 on to the end...

Cheers.
--
  Andy McKay, Developer.
  ActiveState.

- Original Message -
From: "Dyon Balding" [EMAIL PROTECTED]
To: "Andy McKay" [EMAIL PROTECTED]
Cc: "zope-misc" [EMAIL PROTECTED]
Sent: Wednesday, December 13, 2000 12:38 PM
Subject: Re: [Zope] dtml decimals


 or even simpler:

 dtml-var "3.0/2" fmt="%.2f"

 the decimal point implies a floating point rather than an int.

 -d

 On Wed, Dec 13, 2000 at 12:23:19PM -0800, Andy McKay wrote:
  Well there you go:
 
  dtml-var "_.float(3)/_.float(2)" fmt="%.2f"
 
  Its a python thing, it sees 3 and casts it as an int, same with 2 and
  dividing ints results in an int. You learn something new every day.
 
  --
Andy McKay, Developer.
ActiveState.
 
  - Original Message -
  From: "Andy McKay" [EMAIL PROTECTED]
  To: "zope-misc" [EMAIL PROTECTED]
  Sent: Wednesday, December 13, 2000 10:11 AM
  Subject: Re: [Zope] dtml decimals
 
 
   Well for one thing that example should be dtml-var "3/2" fmt="%.2f"
   --
 Andy McKay, Developer.
 ActiveState.
  
   - Original Message -
   From: "Andy McKay" [EMAIL PROTECTED]
   To: "zope-misc" [EMAIL PROTECTED]
   Sent: Wednesday, December 13, 2000 10:03 AM
   Subject: [Zope] dtml decimals
  
  
dtml-var "3/2" fmt="%.2d" instead of getting 1.50 as I was
expecting I
   get
1.00, I never seem to be getting decimals. Whats the obivous thing
Im
missing here?
   
Cheers.
   
--
  Andy McKay, Developer.
  ActiveState.
   
   
___
Zope maillist  -  [EMAIL PROTECTED]
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 )
   
  
  
   ___
   Zope maillist  -  [EMAIL PROTECTED]
   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 )
  
 
 
  ___
  Zope maillist  -  [EMAIL PROTECTED]
  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 )

 --
 Dyon Balding [EMAIL PROTECTED]

 ___
 Zope maillist  -  [EMAIL PROTECTED]
 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 )



___
Zope maillist  -  [EMAIL PROTECTED]
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 )




Re: [Zope] dtml decimals

2000-12-13 Thread Dieter Maurer

Andy McKay writes:
  dtml-var "3/2" fmt="%.2d" instead of getting 1.50 as I was expecting I get
  1.00, I never seem to be getting decimals. Whats the obivous thing Im
  missing here?
This is a Python feature:

  If both arguments are integers, the division is performed
  as an integer division.

  Use "3.0/2" or "3/2.0" or "float(3)/2"  to get a floating point division.


Dieter

___
Zope maillist  -  [EMAIL PROTECTED]
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 )