Programing style
John Craig
jc at spl21.net
Thu Nov 16 16:58:08 EST 2006
The format function may be worth a look at in the docs;
put "$" & format("%1.3f", 12345.678) into tResult
would format to 3 decimal places.
If you are after the thousand seperators, I don't think format can do
that, but I could be wrong.
Here's a snippet that will format with the thousand seperators;
put 12345678.567 into tVal
set itemDel to "."
put item 1 of tVal into tInt
put "." & item 2 of tVal into tDec
repeat with i = length(tInt) - 3 to 1 step -3
if i > 0 then put "," after char i of tInt
end repeat
put "$" & tInt & tDec into tResult
The output is : $12,345,678.567
Hope this is some help
JC
Hershel Fisch 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
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>
More information about the use-livecode
mailing list