sum() produces floats not integers
Hi ya all, When I sum a column decimals(floats) are returned. ie. 2.0, 3.0. but i only want the integer instead of the trailing ".0" I cant seem to work out how to do this however i assume its controlled by the sum() function. Can anyone help me on this? Below is the code fragments which currently work but with the ".0" Zsql SELECT title, SUM(plays) AS plays FROM charts GROUP BY title PageTemplate <TR bgcolor="#333333" tal:repeat="charts here/getChartsMethod"> <span TAL:replace="charts/title">Title</span> <span TAL:replace="charts/plays">Plays</span> </TR> Cheers, wayne __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com
Wayne Connolly wrote at 2003-9-14 21:50 -0700:
When I sum a column decimals(floats) are returned. ie. 2.0, 3.0. but i only want the integer instead of the trailing ".0"
"int" converts to integer. You may want to combine it with "round" or "math.ceil/math.floor". Dieter
Try this:
PageTemplate <TR bgcolor="#333333" tal:repeat="charts here/getChartsMethod"> <span TAL:replace="charts/title">Title</span> <span TAL:replace="python python:'%0.f' % charts.plays">Plays</span> </TR>
cheers, Chris
Thanks so much Chris, there was a minor modification to get it working which was the duplication of the python which im sure was just a typo... . but it was perfect nonetheless. To remove the float from returned database results ::: <span TAL:replace="python:'%0.f' % charts.plays">Plays</span> cheers mate, wayne ----- Original Message ----- From: "Chris Withers" <chrisw@nipltd.com> To: <wayne@c-media.com.au> Cc: <zope@zope.org> Sent: Wednesday, September 17, 2003 10:03 PM Subject: Re: [Zope] sum() produces floats not integers
Try this:
PageTemplate <TR bgcolor="#333333" tal:repeat="charts here/getChartsMethod"> <span TAL:replace="charts/title">Title</span> <span TAL:replace="python python:'%0.f' % charts.plays">Plays</span> </TR>
cheers,
Chris
Wayne Connolly wrote:
Thanks so much Chris, there was a minor modification to get it working which was the duplication of the python which im sure was just a typo...
Yep, was, sorry about that...
. but it was perfect nonetheless. To remove the float from returned database results ::: <span TAL:replace="python:'%0.f' % charts.plays">Plays</span>
cheers mate,
No probs... Chris
participants (4)
-
Chris Withers -
Dieter Maurer -
Wayne Connolly -
Wayne Connolly