Programing style

Ken Ray kray at sonsothunder.com
Thu Nov 16 22:54:11 CST 2006


On 11/16/06 8:58 PM, "Mark Wieder" <mwieder at ahsoftware.net> wrote:

> Hershel-
> 
> Thursday, November 16, 2006, 1:01:34 PM, you wrote:
> 
>> Hi all, I'd like to know how others write a function like this.
> 
> Ooooo... a challenge. First of all, I'd add some comments. Then here's
> what I came up with - rather like John Craig's repeat loop. Not sure
> how you'd want negative values formatted - this will leave them as
> $-123.45.
> 
> FUNCTION fNumericToMoney pNumeric
>     local tMoney
>     local x
>     
>     -- leading dollar sign and two digits for cents
>     put format("$%.2f", pNumeric) into tMoney
>     -- add the commas as necessary
>     -- 4 is to ensure we don't get a comma before the dollar sign
>     -- 6 here is skipping over the first three digits, the period, and the
> cents
>     REPEAT with x=length(tMoney)-6 to 4 step -3
>         -- +1 to skip over the dollar sign
>         put comma before char x+1 of tMoney
>     END REPEAT
>     return tMoney
> END fNumericToMoney

Nicely done, Mark! Hadn't thought of doing it that way...

;-)

Ken Ray
Sons of Thunder Software, Inc.
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com






More information about the use-livecode mailing list