Currency Formatting?
David Vaughan
drvaughan55 at mac.com
Mon Jan 28 17:28:01 EST 2002
Rick
I haven't looked yet for an obvious way in Rev but this is the script I
wrote for use in my HyperCard stacks, so it should do the trick in Rev.
function InsertComma srcNum,symbol
put empty into pretty
-- Find a decimal point, if any
put offset(".",srcNum) into decPoint
put length(srcNum) into srcLen
if decPoint > 0 then
-- Anything from the decimal point needs no further work
put char decPoint to srcLen of srcNum into pretty
-- Shorten the string to the part with which to deal
delete char decPoint to srcLen of srcNum
put (decPoint - 1) into srcLen
end if
-- Now loop inserting commas and breaking off that part
repeat while srcLen > 3
put "," & char (srcLen - 2) to srcLen of srcNum before first char of
pretty
delete char (srcLen - 2) to srcLen of srcNum
put length(srcNum) into srcLen
end repeat
-- Add the optional symbol
put symbol & srcNum before first char of pretty
return(pretty)
end InsertComma
This function returns a comma-delimited number with optional first
symbol (e.g. $ or ¥ or €).
For example, << put insertComma(1234.56,"$") >> produces $1,234.56. For
that matter, << put insertComma("Fred","Apple") >> will produce
"AppleF,red" for what it is worth!
cheers
David
On Tuesday, January 29, 2002, at 03:10 , Rick Harrison wrote:
> Hi there,
>
> I'm pretty new to Revolution.
>
> My question is:
>
> I need to format my output as $9,999,999,999.999999
>
> Is there an easy way to do this?
>
> I looked at the numberFormat thing and the examples aren't
> up to snuff. There doesn't appear to be a way for commas
> etc. to be used.
>
> Any suggestions?
>
> Thanks in advance!
>
> Rick Harrison
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
More information about the use-livecode
mailing list