Currency Formatting?
Rick Harrison
harrison at all-auctions.com
Mon Jan 28 17:53:01 EST 2002
on 1/28/2002 5:26 PM, David Vaughan at drvaughan55 at mac.com wrote:
> 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
>
David,
Thanks for the code segment!!
I'll try it out. It should work...
I just wish that the people who wrote Rev. had
already done this stuff for us. We shouldn't
have to re-invent the wheel!
Thanks again!
Rick Harrison
More information about the use-livecode
mailing list