>Does anyone have a handler to convert a number to a currency?
>
>eg 1234567 > �1,234,567.00
>
>/H
>
>Hugh Senior

Hi Hugh

*** Apologies if I've 'sinned' by including a small attachment, but 
it is the easiest way to provide the requested handler together with 
a demo/test environment. ***

I was intrigued by your request and so came up with a demo stack 
called "currency.mc" which contains the following function:

---------------
function currency rawStr, currSym, beforeAfter, thouSymb, decSym, decPl
  if not isNumber(decPl) or decPl = 0 then
    put round(rawStr) into rawStr
  end if
  put trunc(rawStr) into wholeNumb
  if thouSymb = empty then
    put wholeNumb into currStr
  else
    put empty into currStr
    repeat until wholeNumb < 1000
      put thouSymb & char -3 to -1 of ("000" & wholeNumb mod 1000) 
before currStr
      put wholeNumb div 1000 into wholeNumb
    end repeat
    if wholeNumb = 0 then
      delete first char of currStr
    else
      put wholeNumb before currStr
    end if
    if currStr = empty then put "0" into currStr
  end if
  if isNumber(decPl) and decPl > 0 then put decSym & round((rawStr - 
trunc(rawStr)) * (10 ^ decPl)) after currStr
  if beforeAfter <> "after" then
    put currSym before currStr
  else
    put currSym after currStr
  end if
  return currStr
end currency
---------------

If you look at the above you will see that I've tried to cater for:

1) different currency symbols, which can be before or after the value
2) different thousands symbol (for UK/US vs Europe)
3) different decimal 'point' symbol (for UK/US vs Europe)
4) different number of decimal places (it rounds to specified number)

I hope this does what you want.

Best regards

Peter

%currency.mc

currency.mc

--------------------------------------------------------
Peter Reid
Reid-IT Limited, Loughborough, Leics., UK
Tel: +44 (0)1509 268843 Fax: +44 (0)1509 264986
E-mail: [EMAIL PROTECTED]
Web: http://www.reidit.co.uk

Reply via email to