Try This C# code.
Create a class and name it what ever you want. in my case JayClass then write following custom visual basic functions as shown.
public class JayClass
{
public static object Choose(double index,params object[] choice)
{
if (index < 1 || index > choice.Length)
{
return " ";
}
else
{
return choice[Convert.ToInt32(--index)];
}
}
public static string Mid(string input, int start, int length)
{
string temp = input.Substring(start-1,length);
return temp;
}
public static string Mid(string input, int length)
{
string temp = input.Substring(length);
return temp;
}
public static string Left(string input , int length)
{
string temp = input.Substring(0,length);
return temp;
}
public static string Right(string input, int length)
{
string temp = input.Substring(input.Length-length, length);
return temp;
}
public static string Format(object Exprs, string style = "")
{
string temp = String.Format("{0:"+style+"}",Exprs);
return temp;
}
}
create another class and name what ever you want, in my case Trillion and write the below methode within the class. Yes, "Trillion" because it can translate numeric digits from one up to trillion to words.
public class Trillion{
public static string GET_Trillion(double value)
{
String[] M = new String[9], L = new String[10], K = new String[8], Place = new String[5];
String PN, Results = "";
// ONES IN WORDS
M[0] = "one";
M[1] = "two";
M[2] = "three";
M[3] = "four";
M[4] = "five";
M[5] = "six";
M[6] = "seven";
M[7] = "eight";
M[8] = "nine";
// TENS IN WORDS
L[0] = "ten";
L[1] = "eleven";
L[2] = "twelve";
L[3] = "thirteen";
L[4] = "fourteen";
L[5] = "fifteen";
L[6] = "sixteen";
L[7] = "seventeen";
L[8] = "eighteen";
L[9] = "nineteen";
K[0] = "twenty";
K[1] = "thirty";
K[2] = "forty";
K[3] = "fifty";
K[4] = "sixty";
K[5] = "seventy";
K[6] = "eighty";
K[7] = "ninety";
PN = "and ";
// placement
Place[0] = " hundred ";
Place[1] = " thousand ";
Place[2] = " million ";
Place[3] = " billion ";
Place[4] = " trillion ";
if (value.ToString().Length> 15)
{
throw new Exception(
"OutOfRangeException\nMessage: Please consider setting a value not greater than 15 digits. "
+ value.ToString().Length + (value.ToString().Length > 1 ? " digits Keyed" : " digit Keyed"));
}
if (value.ToString().Length < 0)
{
throw new Exception(
"OutOfRangeException\nMessage: Please consider setting a value atleast not less than one(1) digit "
+ value.ToString().Length + (value.ToString().Length <-1 ? " digits Keyed" : " digit Keyed"));
}
if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 14, 1)) != 1)
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 15, 1)) + 1, "", M[0],
M[1], M[2], M[3], M[4], M[5], M[6], M[7], M[8]);
}
else
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 15, 1)) + 1, L[0], L[1],
L[2], L[3], L[4], L[5], L[6], L[7], L[8], L[9]);
}
if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 14, 1)) > 1
&& Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 15, 1)) > 0)
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 14, 1)) + 1, "", "", K[0],
K[1], K[2], K[3], K[4], K[5], K[6], K[7]) + "-" + Results;
}
else
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 14, 1)) + 1, "", "", K[0],
K[1], K[2], K[3], K[4], K[5], K[6], K[7]) + Results;
}
if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 13, 1)) == 0)
{
}
else if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 14, 1)) == 0
&& Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 15, 1)) == 0)
{
Results = Place[0];
}
else
{
Results = Place[0] + PN + Results;
}
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 13, 1)) + 1, "", M[0], M[1],
M[2], M[3], M[4], M[5], M[6], M[7], M[8]) + Results;
if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 10, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 11, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 12, 1)) == 0)
{
}
else if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 13, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 14, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 15, 1)) == 0
|| Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 13, 1)) != 0)
{
Results = Place[1] + Results;
}
else
{
Results = Place[1] + PN + Results;
}
if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 11, 1)) != 1)
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 12, 1)) + 1, "", M[0],
M[1], M[2], M[3], M[4], M[5], M[6], M[7], M[8]) + Results;
}
else
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 12, 1)) + 1, L[0], L[1],
L[2], L[3], L[4], L[5], L[6], L[7], L[8], L[9]) + Results;
}
if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 11, 1)) > 1
&& Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 12, 1)) > 0)
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 11, 1)) + 1, "", "", K[0],
K[1], K[2], K[3], K[4], K[5], K[6], K[7]) + "-" + Results;
}
else
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 11, 1)) + 1, "", "", K[0],
K[1], K[2], K[3], K[4], K[5], K[6], K[7]) + Results;
}
if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 10, 1)) == 0)
{
}
else if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 11, 1)) == 0
&& Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 12, 1)) == 0)
{
Results = Place[0] + Results;
}
else
{
Results = Place[0] + PN + Results;
}
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 10, 1)) + 1, "", M[0], M[1],
M[2], M[3], M[4], M[5], M[6], M[7], M[8]) + Results;
if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 7, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 8, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 9, 1)) == 0)
{
}
else if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 10, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 11, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 12, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 13, 1)) == 0
&& Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 14, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 15, 1)) > 0)
{
Results = Place[2] + PN + Results;
}
else
{
Results = Place[2] + Results;
}
if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 8, 1)) != 1)
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 9, 1)) + 1, "", M[0], M[1],
M[2], M[3], M[4], M[5], M[6], M[7], M[8]) + Results;
}
else
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 9, 1)) + 1, L[0], L[1],
L[2], L[3], L[4], L[5], L[6], L[7], L[8], L[9]) + Results;
}
if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 8, 1)) > 1
&& Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 9, 1)) > 0)
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 8, 1)) + 1, "", "", K[0],
K[1], K[2], K[3], K[4], K[5], K[6], K[7]) + "-" + Results;
}
else
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 8, 1)) + 1, "", "", K[0],
K[1], K[2], K[3], K[4], K[5], K[6], K[7]) + Results;
}
if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 7, 1)) == 0)
{
}
else if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 8, 1)) == 0
&& Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 9, 1)) == 0)
{
Results = Place[0] + Results;
}
else
{
Results = Place[0] + PN + Results;
}
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 7, 1)) + 1, "", M[0], M[1],
M[2], M[3], M[4], M[5], M[6], M[7], M[8]) + Results;
if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 4, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 5, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 6, 1)) == 0)
{
}
else if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 7, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 8, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 9, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 10, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 11, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 12, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 13, 1)) == 0
&& Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 14, 1)
+ JayClass.Right(JayClass.Format(value, "000000000000000"), 1)) > 0)
{
Results = Place[3] + PN + Results;
}
else
{
Results = Place[3] + Results;
}
if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 5, 1)) != 1)
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 6, 1)) + 1, "", M[0], M[1],
M[2], M[3], M[4], M[5], M[6], M[7], M[8]) + Results;
}
else
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 6, 1)) + 1, L[0], L[1],
L[2], L[3], L[4], L[5], L[6], L[7], L[8], L[9]) + Results;
}
if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 5, 1)) > 1
&& Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 6, 1)) > 0)
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 5, 1)) + 1, "", "", K[0],
K[1], K[2], K[3], K[4], K[5], K[6], K[7]) + "-" + Results;
}
else
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 5, 1)) + 1, "", "", K[0],
K[1], K[2], K[3], K[4], K[5], K[6], K[7]) + Results;
}
if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 4, 1)) == 0)
{
}
else if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 5, 1)) == 0
&& Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 6, 1)) == 0)
{
Results = Place[0] + Results;
}
else
{
Results = Place[0] + PN + Results;
}
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 4, 1)) + 1, "", M[0], M[1],
M[2], M[3], M[4], M[5], M[6], M[7], M[8]) + Results;
if (Convert.ToDouble(JayClass.Left(JayClass.Format(value, "000000000000000"), 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 2, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 3, 1)) == 0)
{
}
else if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 4, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 5, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 6, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 7, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 8, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 9, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 10, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 11, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 12, 1)
+ JayClass.Mid(JayClass.Format(value, "000000000000000"), 13, 1)) == 0
&& Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 14, 1)
+ JayClass.Right(JayClass.Format(value, "000000000000000"), 1)) > 0)
{
Results = Place[4] + PN + Results;
}
else
{
Results = Place[4] + Results;
}
if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 2, 1)) != 1)
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 3, 1)) + 1, "", M[0], M[1],
M[2], M[3], M[4], M[5], M[6], M[7], M[8]) + Results;
}
else
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 3, 1)) + 1, L[0], L[1],
L[2], L[3], L[4], L[5], L[6], L[7], L[8], L[9]) + Results;
}
if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 2, 1)) > 1
&& Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 3, 1)) > 0)
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 2, 1)) + 1, "", "", K[0],
K[1], K[2], K[3], K[4], K[5], K[6], K[7]) + "-" + Results;
}
else
{
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 2, 1)) + 1, "", "", K[0],
K[1], K[2], K[3], K[4], K[5], K[6], K[7]) + Results;
}
if (Convert.ToDouble(JayClass.Left(JayClass.Format(value, "000000000000000"), 1)) == 0)
{
}
else if (Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 2, 1)) == 0
&& Convert.ToDouble(JayClass.Mid(JayClass.Format(value, "000000000000000"), 3, 1)) == 0)
{
Results = Place[0] + Results;
}
else
{
Results = Place[0] + PN + Results;
}
Results = (String)JayClass.Choose(
Convert.ToDouble(JayClass.Left(JayClass.Format(value, "000000000000000"), 1)) + 1, "", M[0], M[1], M[2],
M[3], M[4], M[5], M[6], M[7], M[8]) + Results;
return Results;
}
}
Assuming you input this number, "9,999,999,999,999" it will be translated to words exactly like this "nine trillion nine hundred and ninety-nine billion nine hundred and ninety-nine million nine hundred and ninety-nine thousand nine hundred and ninety-nine"
Use it and thank me later.