Spell numbers to words with currency (script help)

Spell numbers to words with currency (script help)

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!
  1. string Num2Words(int val)
  2. {
  3. val_s = val.toString();
  4. th = {"","thousand","million","billion","trillion"};
  5. dg = {"zero","one","two","three","four","five","six","seven","eight","nine"};
  6. tn = {"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
  7. tw = {"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
  8. x = val_s.length();
  9. if(x > 15)
  10. {
  11. return "too big";
  12. }
  13. else
  14. {
  15. s = val_s.replaceAll("(?)",",",false).removeFirstOccurence(",").removeLastOccurence(",").toList();
  16. str = "";
  17. sk = 1;
  18. bypass = false;
  19. for each index i in s
  20. {
  21. cur = s.get(i).toLong();
  22. if(!bypass)
  23. {
  24. if((x - i) % 3 == 2)
  25. {
  26. if(cur == 1)
  27. {
  28. next = s.get(i + 1).toLong();
  29. str = str + tn.get(next) + " ";
  30. bypass = true;
  31. sk = 1;
  32. }
  33. else if(cur != 0)
  34. {
  35. str = str + tw.get(cur - 2) + " ";
  36. sk = 1;
  37. }
  38. }
  39. else if(cur != 0)
  40. {
  41. str = str + dg.get(cur) + " ";
  42. if((x - i) % 3 == 0)
  43. {
  44. str = str + "hundred ";
  45. sk = 1;
  46. }
  47. }
  48. }
  49. else
  50. {
  51. bypass = false;
  52. }
  53. if((x - i) % 3 == 1)
  54. {
  55. if(sk != 0)
  56. {
  57. str = str + th.get(floor((x - i - 1) / 3)) + " ";
  58. sk = 0;
  59. }
  60. }
  61. }
  62. return str;
  63. }
  64. }