Script to format a currency value

Peter Haworth pete at
Mon Feb 28 23:55:21 EST 2011

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

More information about the Use-livecode mailing list