Programing style

Sarah Reichelt sarah.reichelt at gmail.com
Thu Nov 16 18:59:12 EST 2006


On 11/17/06, Hershel Fisch <hershf at rgllc.us> wrote:
> Hi all, I'd like to know how others write a function like this.
> TIA Hershel
>
> function fNumericToMoney
>   put param(1) into tParam
>   if tParam contains "." then
>     put offSet(".",tParam)-1 into tTs
>     put 3 into tC
>   else
>     put the number of chars in tParam into tTs
>     put 0 into tC
>   end if
>   repeat while tTs >3
>     add 3 tC
>     put "," before char -tC in tParam
>     add 1 to tC
>     subtract 3 from tTs
>   end repeat
>   return "$" & tParam
> end fNumericToMoney
>

This is very similar to the function I use, although I would recommend
specifying a parameter instead of just using the params.

Also, you need to check that the number doesn't already contain any
commas or dollar signs, so replace them with empty before you start.
Then add a check for the parameter actually being a number.

Sarah



More information about the use-livecode mailing list