Number format for money
Ken Ray
kray at sonsothunder.com
Sun Aug 8 23:30:05 EDT 2004
On 8/8/04 6:17 PM, "Bill" <bill at bluewatermaritime.com> wrote:
> set the numberFormat of tBondAmount to "#.00"
>
> Only works for scroll bars (weird that it is so specialized).
>
> How do you take a number like 10000000.00 that is in the variable
> tBondAmount and make it look like $100,000,000.00 ??
Well, you can't do it directly with numberFormat. You need to do something
like this:
on mouseUp
ask "Enter a value:"
if it <> "" then
put ConvertToDollars(it)
end if
end mouseUp
function ConvertToDollars pAmt
split pAmt by "."
-- pAmt[1] contains the dollars, pAmt[2] contains the cents
if pAmt[2] = "" then put "00" into pAmt[2]
if length(pAmt[2]) = 1 then put "0" after pAmt[2]
put trunc(length(pAmt[1])/3) into tNumLoops
put "" into tDollars
repeat tNumLoops
put "," & char -3 to -1 of pAmt[1] before tDollars
delete char -3 to -1 of pAmt[1]
end repeat
put pAmt[1] & tDollars & "." & pAmt[2] into tRetVal
-- remove a preceding comma if an even multiple of 3
if char 1 of tRetVal = "," then delete char 1 of tRetVal
return "$" & tRetVal
end ConvertToDollars
Hope this helps,
Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com
More information about the use-livecode
mailing list