[Zope] Probably too much to hope for but...

Goldthwaite, Joe invalid at bar-s.com
Sat Dec 6 17:12:23 EST 2003


Thanks Jim,

That's what I was looking for.  I had already gotten it to work from Python but that was causing me to mix my business login with the presentation logic which is supposed to be a no no.  I'm seriously about putting everything into external python modules and just returning HTML.  I think that may make it easier for some things.  It looks like Zope has a lot more number and time formatting functions than Python so I'm still undecided.

Thanks.  It helps a lot.
Joe Goldthwaite

-----Original Message-----
From: Jim Washington [mailto:jwashin at vt.edu]
Sent: Thursday, December 04, 2003 5:11 PM
To: joe at goldthwaites.com
Cc: zope at zope.org
Subject: Re: [Zope] Probably too much to hope for but...


Goldthwaite, Joe wrote:

>Anyone know how to get a number rounded to a whole number and formatted with
>commas between the thousands and parens around negative numbers?
>
>In other words, how to get this; -1234567.55
>To this: (1,234,568)
>
>I can see in The Zope Book that you can use Python string formats like;
>
><p tal:content="python:'%0.0f' % item.YTDCurrent")
>
>That rounds it to the nearest dollar but I can't find where to put the
>parens and commas.
>
>  
>
Hi, Joe

thousands_commas is already available in zope.  So, you can make a 
Script (python) that looks something like:

script name: nearest_dollar_thousands_commas_negative_parens
param : aVal

#round-off, do thousands_commas and put parens around it if negative
from Products.PythonScripts.standard import thousands_commas
zero = 0.0
if not same_type(aVal,zero):
    aVal = float(aVal)
rounded = '%0.0f' % aVal
isNegative = aVal < zero and not float(rounded) == zero
v = thousands_commas(rounded).replace('-','')
if isNegative:
  v = '(%s)' % (v)
return v
Then call it:

<p tal:content=
"python:context.nearest_dollar_thousands_commas_negative_parens(item.YTDCurrent)


-- Jim Washington


Property of Bar-S Foods. This message is intended only for the use of the Addressee and may contain information that is PRIVILEGED and CONFIDENTIAL.  If you are not the intended recipient, dissemination of this communication is prohibited.  If you have received this communication in error, please erase all copies of the message and its attachments and notify us immediately at 602.264.7272 or postmaster at bar-s.com.




More information about the Zope mailing list