Delimiting thousandths..converting 12345678 to 12, 345, 678 for example
Ken Ray
kray at sonsothunder.com
Tue Jun 12 18:39:54 EDT 2007
On Tue, 12 Jun 2007 21:46:48 +0000, Mark E. Powell wrote:
> If there a built-in "thousandths delimit" function that takes a
> number and inserts the appropriate delimiter (e.g. commas for USA).
> Alternately, does someone have an idea for a really fast and
> efficient custom function that does it? I have maybe a hundred
> thousand numbers at a time to convert and cannot think of how to do
> it reliably in less than a dozen lines of code.
Here you go - this is based on a function that Mark Wieder created:
function formatThousands pNum,pSeparator
repeat with x = length(pNum)-3 to 3 step -3
put pSeparator before char x+1 of pNum
end repeat
return pNum
end formatThousands
To call it:
put formatThousands("10000000",",")
--> 10,000,000
Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
More information about the use-livecode
mailing list