Hello,
I came across the following script that spells out numbers to words (many thanks to whoever wrote it, can't seem to find the source anymore). However, I do need to customize this script a little bit and include several currency denominations such as Euros and US Dollars (Currency will be selected from a Dropdown field).
E.g. 1: 15000.50 EUR => Fifteen thousand Euros and fifty cents.
E.g. 2: 15000.50 USD => Fifteen thousand US Dollars and fifty cents
Can some please show me how can this be accomplished?
Thank you very much!
- string Num2Words(int val)
- {
- val_s = val.toString();
- th = {"","thousand","million","billion","trillion"};
- dg = {"zero","one","two","three","four","five","six","seven","eight","nine"};
- tn = {"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
- tw = {"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
- x = val_s.length();
- if(x > 15)
- {
- return "too big";
- }
- else
- {
- s = val_s.replaceAll("(?)",",",false).removeFirstOccurence(",").removeLastOccurence(",").toList();
- str = "";
- sk = 1;
- bypass = false;
- for each index i in s
- {
- cur = s.get(i).toLong();
- if(!bypass)
- {
- if((x - i) % 3 == 2)
- {
- if(cur == 1)
- {
- next = s.get(i + 1).toLong();
- str = str + tn.get(next) + " ";
- bypass = true;
- sk = 1;
- }
- else if(cur != 0)
- {
- str = str + tw.get(cur - 2) + " ";
- sk = 1;
- }
- }
- else if(cur != 0)
- {
- str = str + dg.get(cur) + " ";
- if((x - i) % 3 == 0)
- {
- str = str + "hundred ";
- sk = 1;
- }
- }
- }
- else
- {
- bypass = false;
- }
- if((x - i) % 3 == 1)
- {
- if(sk != 0)
- {
- str = str + th.get(floor((x - i - 1) / 3)) + " ";
- sk = 0;
- }
- }
- }
- return str;
- }
- }