Number format for money

Yves COPPE yvescoppe at skynet.be
Mon Aug 9 04:46:48 EDT 2004


Le 09-août-04, à 01:17, Bill a écrit :

> 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 ??
>
> Bill
>
> -- thanks in adavance!
>
>

Hi Bill,

a time ago, someone on the list gave an universal function for money, 
separator,...

I don't know who was this rev user but his function is very interesting.

here is the function :

function currency rawStr, currSym, beforeAfter, thouSymb, decSym, decPl
   -- Parameters:
   -- rawstr - unformatted number
   -- currSym - currency symbol (can be more than 1 char)
   -- beforeAfter -  symbol is "before" or "after" the value
   -- thouSymb - thousands separator symbol
   -- decSym - decimal point symbol
   -- decPl - number of decimal places
   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 rawStr - trunc(rawStr) into tmp
     if tmp = "0" then
       put decSym & "00" after currStr
     end if

     if char -3 to -1 of currStr <> ",00" then

       if char (offset(".",rawStr))+1 of rawStr = "0" then
         put decSym &"0"&round((rawStr - trunc(rawStr)) * (10 ^ decPl)) 
after currStr
       else
         put decSym & round((rawStr - trunc(rawStr)) * (10 ^ decPl)) 
after currStr
       end if
     end if


   end if
   if beforeAfter <> "after" then
     put currSym before currStr
   else
     put currSym after currStr
   end if
   return currStr
end currency



hope this help.

Greetings.

Yves COPPE
yvescoppe at skynet.be


More information about the use-livecode mailing list