[Zope] Probably too much to hope for but...
Jim Washington
jwashin at vt.edu
Thu Dec 4 19:11:19 EST 2003
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
More information about the Zope
mailing list