Formatting numbers

Gregory Lypny gregory.lypny at videotron.ca
Sat Jan 14 01:15:25 EST 2006


Hello Marty,

I use the following.  It could use a little editing, but it works  
with positive and negative real numbers.

	Gregory

function commaFormat x
   if x is not a number
   then
     return "Error: not a number"
     exit commaFormat
   else
     put trunc(abs(x)) into truncAbsX
     repeat until length(truncAbsX) mod 3 = 0
       put "d" before truncAbsX
       add 1 to dCount
     end repeat
     repeat with i=1 to (length(truncAbsX) div 3)
       put char 1 to 3 of truncAbsX into item i of y
       delete char 1 to 3 of truncAbsX
     end repeat
     if dCount > 0 then delete char 1 to dCount of first item of y
     if x < 0 then put "-" before y
     if abs(x-trunc(x)) is not 0 then add abs(x-trunc(x)) to last  
item of y
     return y
   end if
end commaFormat


On 13-Jan-06, at 10:37 PM, Marty Knapp wrote:

> Message: 21
> Date: Fri, 13 Jan 2006 15:40:10 -0800
> From: Marty Knapp <martyknapp at comcast.net>
> Subject: Formatting numbers
> To: Revolution User List <use-revolution at lists.runrev.com>
> Message-ID: <43C83A5A.2050809 at comcast.net>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> 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




More information about the use-livecode mailing list