Is there a library or a class/function that I can use to convert an integer to it\'s verbal representation?
Example input:
4,567,788`
Solution that takes up less code.
The most important part is only couple lines:
static Func remainder = t => t > 0 ? " " + ToEN(t) : "";
public static string ToEN(this long val, double d = 20, long th = 20)
{
switch ((long)d)
{
case 20: return val >= d ? ToEN(val, 1e2) : en[val];
case 100: return val >= d ? ToEN(val, 1e3, 100) : en[val / 10 * 10] + remainder(val % 10);
default: return val >= d ? ToEN(val, d * 1e3,(long)d) : ToEN(val / th) + " " + en[th] + remainder(val % th);
}
}
Full code is available here https://dotnetfiddle.net/wjr4hF