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

Jim Ault JimAultWins at yahoo.com
Wed Jun 13 15:00:48 EDT 2007


Hello, Hugh,

In my last script, I did accommodate the comma/period alternative by using
"itemDel" to form the result string, therefore the default itemDel for Rev
would be comma thus if pSeparator was "." just use the default of "," for
the decimal separator.

 if pSeparator is "," then set the itemDel to "."
 --  should be the only line required
--since, the itemDel is comma by default at the start of the function
---------------------

As far as "0.00", the user may not want the decimals changed to that format.
We do statistics work, and often want only  0 or 1 decimal and no
reformatting of the decimals by a function.  If there is no decimal in pNum,
it returns no decimal.  This would be true of inventory reports, number of
skiers injured in the Alps each year, Rev programmers I have met in person,
the number of drivers that go fast on the autobahn.

...which means my prev function should have one line corrected:
if holdDec is not empty then put holdDec into item 2 of it
--if there is none, don't add the trailing decimal point.

----
If this is indeed a currency function, then I guess this is the spot where
you would have to define the function precisely, such as pNum must be a
number, instead of a number string to which we are adding commas.

(eg.  $3456.78  or -$3456.78  or $3456.78 - )

By capturing the leading and trailing characters verbatim, this should
accommodate 
--any currency symbol passed as part of the string pNum
--negative symbol format as trailing
--any number of chars after the decimal
but you are correct in that my version would not insert a currency symbol or
format "0.00"

Of course, this is why universal functions are difficult to write.  A tool
for many purposes may become less and less convenient.

Jim Ault
Las Vegas

On 6/13/07 9:59 AM, "FlexibleLearning at aol.com" <FlexibleLearning at aol.com>
wrote:

>  
>  
> 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
>  
> 
> 
> 
>    
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution





More information about the use-livecode mailing list