Formatting numbers
Jim Ault
JimAultWins at yahoo.com
Fri Jan 13 19:52:26 EST 2006
On 1/13/06 3:40 PM, "Marty Knapp" <martyknapp at comcast.net> wrote:
> Does somebody have a suggestion for formatting numbers with commas for a
> printed report?
--Try this ... using recursion (a func calling itself repeatedly) :-)
---------- start copy here ---------------------------------
function commaStart pNumber
set the itemdel to "."
return commaNext(item 1 of pNumber) & "." & item 2 of pNumber
end commaStart
function commaNext pSegment
put char -3 to -1 of pSegment into tPart
get char 1 to -4 of pSegment
if char -3 of it is not empty then get commaNext(it)
return it & comma & tPart
end commaNext
---end of the functions here ---------------------------------------
--you can do a quick test by copying all this code into a new stack script
and double clicking
on mousedoubleup
put 24564646543456789.22 into origNumber
put commaStart(origNumber) & " < "& origNumber into msg
end mousedoubleup
----- end copy of test code----------------
--This is a two-part function, commaStart() and commaNext(). You need both
for this to work.
--The function commaNext will be called as often as there is more than 3
chars left in pSegment. This is called recursion and is used especially int
the cas of walking down all sub folder paths
--The key line of code is "get char 1 to -4 of pSegment" which captures the
remaining digits. If there are more than 3, then we need to call commaNext
again.
Jim Ault
Las Vegas
On 1/13/06 3:40 PM, "Marty Knapp" <martyknapp at comcast.net> wrote:
> Does somebody have a suggestion for formatting numbers with commas for a
> printed report? It wil have columns of data, with numbers ranging from
> small to large. The larger ones are hard to read, so I'd like to insert
> commas at the appropriate places. I can think of clunky ways to do it,
> but thought I'd ask here in case someone had already brewed up something
> nice.
>
> Thanks,
>
> Marty Knapp
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
More information about the use-livecode
mailing list