string Num2Words(int val)
{
val_s = input.val.toString();
th = {"", "thousand", "million", "billion", "trillion"};
// uncomment this line for English Number System
// th = {"","thousand","million", "milliard","billion"};
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;
}
}