May 11, 2010

How to Convert Numbers to Currency

The NumberToCurrency function will translate a numeric value into a phrase representing an amount in a currency, for example:

«NumberToCurrency(price,'Pound','Pounds','Penny','Pence', 'only','en','Leave')»

The parameters are the singular and plural values of the denomination, the ‘only’ parameter is what must be printed if the number of pence is zero, and the last two parameters are the language and case conversion, respectively.

The above example would render the amount 1234 as One Thousand Two Hundred and Thirty Four Pounds only.

The languages supported are:

af : Afrikaans
de : German
en : English (USA) (the default)
en-uk,en-gb : English (Great Britain)
en-za : English (South Africa)
es : Spanish
fr : French

There are a number of variations of this function, for the common currencies and languages, each of which takes two parameters, viz. the amount to be represented as currency, and the case (i.e ToUpper, ToLower, etc.). The default for the case is Leave. These variations are shown below as examples of usage:

«Dolares(Amount)»
«Dollars(Amount)»
«DollarsFrancaise(Value)»
«EuroDeutsch(Preis)»
«EurosEspanol(Value)»
«EurosFrancaise(Value)»
«Pesos(Price)»
«Pounds(Price,ToUpper)»
«Rand(SellingPrice)»
«RandAfrikaans(PurchaseAmount)»