Rick, did you try casting "number" to a string before the slice operation? Just a stab in the dark. Eric. D. Rick Anderson wrote:
You can format it using fmt=dollars-and-cents or fmt="%.2f", but in this case where there is a e- in the string it simply zeros it out. I am clipping the string back to 10 characters (none of the values in there should be longer than that anyway) and in doing so clipping off the e- before then turning it into a float. It's the number[0:10] that is barfing.
Rick
Doesn't dtml have a function to do that? Check the zope book.
From: "D. Rick Anderson" <ruger@comnett.net> Reply-To: ruger@comnett.net Date: Thu, 7 Feb 2002 13:43:10 -0800 (PST) To: zope@zope.org Subject: [Zope] problem with python script
I am having a horrible time with a python script. The idea is to get a dollars-and-cents formatted string from the 3.87987234233e-1234 type string that the Sybase server is returning. The python script looks like this: --- final = (float(int(float(number[0:10]) * 100)) / 100)
return final