Currency Formatting?
Jan Decroos
jan.decroos at groepvanroey.be
Tue Jan 29 03:25:01 EST 2002
the function dispnum (see below) does the job.
dispnum :
first argument : true/false to put or remove the thousand and decimal separator
2nd argument : the container with numbers
change the lThousSep and lDecimSep variables if you want to have other
separators (in Europe we take the comma for the decimal separator and a space
or point for the thousand separator)
on mouseUp
ask "Give Amount:" with 12345678.888
if it <> "" then answer "$"&dispnum(true,it)
end mouseUp
function dispnum pOption, pData
if last char of pData = CR then put CR after pData
-- change next two lines depending on your needs
put comma into lThousSep
put "." into lDecimSep
if not(pOption) then -- UNdisplay (back to numbers)
put pData into lResult
replace lThousSep with "" in lResult
replace lDecimSep with "." in lResult
else -- make numbers readable
repeat for each line lLine in pData
if lLine is a number then
put offset(".",lLine) into lPosPnt
put (lPosPnt = 0) into lisInteger -- don't check by "is an integer"
because "5.00" is an integer !!
if lisInteger then put length(lLine) into lEnd
else put lPosPnt-1 into lEnd
if char 1 of lLine = "+" or char 1 of lLine = "-" then put 1 into
lOffset
else put 0 into lOffset
if not(lisInteger) then put lDecimSep into char lEnd+1 of lLine
put 3 into lChar
repeat ((lEnd - 1 - lOffset) DIV 3)
put lThousSep before char lEnd-lChar+1 of lLine
add 3 to lChar
end repeat
end if
put lLine&CR after lResult
end repeat
if last char of lResult = CR then delete last char of lResult
end if
return (lResult)
end dispnum
Hope this helps...
Jan
More information about the use-livecode
mailing list