Script to format a currency value

Alex Tweedly alex at tweedly.net
Tue Mar 1 19:42:28 EST 2011


I'm curious  is there really a real-life use-case for the group spec ? 
i.e. variable size groupings of digits ?

Not sure what order you want for currency and neg sign ?   Should it be
    $-123  or -$123
and should it be 123-$  or  123$-  ?

Should there always be a 0 before the "point" ?  i.e. could the result   
be   .12  rather than 0.12 ?
How about -.12 rather than -0.12 ?

Thanks for a fun challenge ....
-- Alex.



On 01/03/2011 04:55, Peter Haworth wrote:
> OK, here's an amusing exercise in scripting for you experts out there, but I'm giving away a prize!  I will give the person who provides the best solution a copy of my band's latest CD, Aged 10 years.  the definition of "best" is strictly my opinion!  If you don;t like traditional Celtic music (including bagpipes), we;ll just do the script for the fun of it and sell the CD on eBay!!!
>
> You have an integer value that needs to be formatted into a currency value.  It is stored as a positive or negative binary value no matter how many decimal places it has (eg 10000 = $100.00). You have the following formatting characters to deal with:
>
> currency symbol: always present
>
> currency symbol position: 1 = before the number, 0=after the number
>
> decimal delimiter :  could be empty
>
> number of decimals: could be zero and will be if decimal point char is empty
>
> negative sign character: always present
>
> negative sign position: 1= at the start of the formatted number , 0= at the end of the formatted number
>
> group separator character: Specifies the character separator used for grouping digits to the left of the decimal delimiter in formatted monetary quantities.  Could be present even if no decimal delimiter is specified.  Also could be empty, meaning no grouping.
>
> grouping spec:  Specifies a string that defines the size of each group of digits in formatted monetary quantities. Only present if the group separator is not empty. Consists of a sequence of semicolon-separated integers. Each integer specifies the number of digits in a group. The initial integer defines the size of the group immediately to the left of the decimal delimiter. The following integers define succeeding groups to the left of the previous group. If the last integer is not -1, the size of the previous group (if any) is repeatedly used for the remainder of the digits. If the last integer is -1, no further grouping is performed.
>
> Deadline is midnight Friday March 4th, California time.  Good luck!
>
> Pete Haworth
>
>
>
>
>
>
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>





More information about the Use-livecode mailing list