Delimiting thousandths..converting 12345678 to 12, 345, 678 for example

FlexibleLearning at aol.com FlexibleLearning at aol.com
Wed Jun 13 12:59:33 EDT 2007


 
 
I will add arbitrary and optional currency (£ $ YEN etc) and alternative  
decimal (some countries use "." for the thousands and "," for the decimal) with  
0.00 numberFormatting...


 

on mouseUp
put formatThousands(fld 1,"LAT",". ",",")
end mouseUp
 
function formatThousands pNum,pCurrency,pSeparator,pDecimal
--|  Syntax: formatThousands pNum[,pCurrency[,pSeparator[,pDecimal]]]
  if pNum is not a number then return "ERR: Not a number"
if char 1 of pNum = "-" then
put "-" into  prefix
put char 2 to -1 of pNum into pNum
end  if
if pSeparator="" then put "," into pSeparator
if  pDecimal="" then put "." into pDecimal
set the numberFormat to  "0.00"
add 0 to pNum
set the itemDel to "."
put  item 2 of pNum into holdDec
put item 1 of pNum into pNum
repeat with x = length(pNum)-3 to 3 step -3
put pSeparator  before char x+1 of pNum
end repeat
return (pCurrency  && prefix & pNum & pDecimal & holdDec)
end  formatThousands
 
/H
 



   



More information about the use-livecode mailing list