Function of convert number into text
public static string NumberToText(int n)
{
if (n < 0)
return "Minus " + NumberToText(-n);
else if (n == 0)
return "";
else if (n <= 19)
return new string[] {"ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT",
"NINE", "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN",
"SEVENTEEN", "EIGHTEEN", "NINETEEN"}[n - 1] + " ";
else if (n <= 99)
return new string[] {"TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY",
"EIGHTY", "NINETY"}[n / 10 - 2] + " " + NumberToText(n % 10);
else if (n <= 199)
return "ONE HUNDRED " + NumberToText(n % 100);
else if (n <= 999)
return NumberToText(n / 100) + "HUNDRED " + NumberToText(n % 100);
else if (n <= 1999)
return "ONE THOUSAND " + NumberToText(n % 1000);
else if (n <= 99999)
return NumberToText(n / 1000) + "THOUSAND " + NumberToText(n % 1000);
else if (n <= 199999)
return "ONE LAC " + NumberToText(n % 100000);
else if (n <= 9999999)
return NumberToText(n / 100000) + "LAC " + NumberToText(n % 100000);
else if (n <= 19999999)
return "ONE CRORE" + NumberToText(n % 10000000);
else if (n <= 999999999)
return NumberToText(n / 10000000) + "CRORE " + NumberToText(n % 10000000);
else if (n <= 1999999999)
return "ONE BILLION " + NumberToText(n % 1000000000);
else
return NumberToText(n / 1000000000) + "BILLION " + NumberToText(n % 1000000000);
}
public static string NumberToText(int n)
{
if (n < 0)
return "Minus " + NumberToText(-n);
else if (n == 0)
return "";
else if (n <= 19)
return new string[] {"ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT",
"NINE", "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN",
"SEVENTEEN", "EIGHTEEN", "NINETEEN"}[n - 1] + " ";
else if (n <= 99)
return new string[] {"TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY",
"EIGHTY", "NINETY"}[n / 10 - 2] + " " + NumberToText(n % 10);
else if (n <= 199)
return "ONE HUNDRED " + NumberToText(n % 100);
else if (n <= 999)
return NumberToText(n / 100) + "HUNDRED " + NumberToText(n % 100);
else if (n <= 1999)
return "ONE THOUSAND " + NumberToText(n % 1000);
else if (n <= 99999)
return NumberToText(n / 1000) + "THOUSAND " + NumberToText(n % 1000);
else if (n <= 199999)
return "ONE LAC " + NumberToText(n % 100000);
else if (n <= 9999999)
return NumberToText(n / 100000) + "LAC " + NumberToText(n % 100000);
else if (n <= 19999999)
return "ONE CRORE" + NumberToText(n % 10000000);
else if (n <= 999999999)
return NumberToText(n / 10000000) + "CRORE " + NumberToText(n % 10000000);
else if (n <= 1999999999)
return "ONE BILLION " + NumberToText(n % 1000000000);
else
return NumberToText(n / 1000000000) + "BILLION " + NumberToText(n % 1000000000);
}