Coerce number into numberFormatted integer--How?

Dar Scott dsc at swcp.com
Wed Jul 10 11:06:01 EDT 2002


On Tuesday, July 9, 2002, at 11:47 PM, Sivakatirswami wrote:

> So, we can see it *is* working.. But how to coerce the simple 
> integer that
> is not a result of math into the dollar format... I *can* just "fake" a
> calculation put (1*tShipping) into tShipping. And that works, but, 
> hoping
> not to have to be doing that in the long term, as one day someone else
> looking at the code will be asking "What is That for?" I suppose 
> if there is
> no other option we will just explain that line with a comment... 
> And end up
> with two extra lines of workaround code.

First the creation of dollar strings

You can make a few functions called dollar and dollarComma and 
dollarCommaSign, or some better names you think up.  The first 
simply uses round to round to two digits; it is for math.  Use it 
on the result of every every multiply involving money.  For display 
or output always use dollarComma and dollarCommaSign.  The first 
adds 0 to force to number, uses numberFormat and, say, "& empty" to 
force to string and then adds the commas for multiples of $1,000.  
The second takes that and adds $.  You might want dollarComma to 
throw if the arg is not a number.

If you want to make sure functions return money, insert the 
appropriate function into your return commands.  Comments about 
numberFormat are only in one place.

The next I would do is ask how that 8 got there.  Shouldn't that 
process have put it into the form you want?  (If you use the above 
functions for display, it shouldn't matter though.)

Applying numberFormat to every return would require math functions 
we write to have to set numberFormmat every time and would use up 
cpu cycles for every return and for every use of functions.

Dar Scott




More information about the Use-livecode mailing list