Formatting numbers

Marty Knapp martyknapp at comcast.net
Fri Jan 13 19:54:11 EST 2006


Thanks Peter, I'll give it a whirl.

Marty

> Here is what I use, not sure if it the best, but it works for any size 
> number:
>
> function AddNumberSeparator pValue
>   local  tDecimalPointPos, tLength, tSeparatorPosition
>
>    put offset(".",pValue) into tDecimalPointPos
>    put the number of chars in pValue into tLength
>    if tDecimalPointPos is not zero then put tDecimalPointPos - 1 into 
> tLength
>    put tLength - 3 into tSeparatorPosition
>    repeat while tSeparatorPosition > 0
>      put char 1 to tSeparatorPosition of pValue & "," & char 
> tSeparatorPosition + 1 to -1 of pValue into pValue
>      subtract 3 from tSeparatorPosition
>    end repeat
>    return pValue
>
> end AddNumberSeparator
>
> At 05:40 PM 1/13/2006, you 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
>



More information about the use-livecode mailing list