Money Script

FlexibleLearning admin at
Tue Aug 9 02:02:14 EDT 2011

This also handles negative values...

Mark Wieder's script, adjusted to optionally support an arbitrary currency

on mouseUp
  put fNumericToMoney (fld "Value",fld "Sign") into fld "currency"
end mouseUp

function fNumericToMoney pNumeric,pSign
  local tMoney
  local x

  -- leading dollar sign and two digits for cents
  if pSign="" then put "$" into pSign
  put pNumeric<0 into isNeg
  put abs(pNumeric) into pNumeric
  put format(pSign&"%.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
  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
  if isNeg then put "-" before tMoney
  return tMoney
end fNumericToMoney

Hugh Senior

More information about the Use-livecode mailing list