Programing style

Mark Wieder mwieder at ahsoftware.net
Thu Nov 16 21:58:59 EST 2006


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

-- 
-Mark Wieder
 mwieder at ahsoftware.net




More information about the use-livecode mailing list