//This methos converts Digits to Words
//Implementation is to just copy this method and use it.
//Pass any number and will get string in return.
//Example: 120345
//Output is :One Lac(s) Twenty Thousands Fourty Five Only
private string DigitToWord(long n)
{
string[] list = new string[] { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Ninteen", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninty" };
string[] pos = new string[] { "Arab", "Crore", "Lac(s)", "Thousand", "Hundred" };
int[] arr = new int[10];
int i = 0, j, k, count, opt = 1;
string strWord = "";
count = 0;
if (n == 0)
strWord = "zero";
else
{
j = 0;
while (n != 0)
{
arr[j] = (int)n % 10;
n = n / 10;
count++;
j++;
}
for (i = count - 1; i >= 0; i--)
{
k = (9 - i) / 2;
j = arr[i];
if (j == 0)
continue;
else
{
if (i > 2)
{
if (i % 2 != 0)
{
strWord += " " + list[j - 1];
strWord += " " + pos[k];
}
if (i % 2 == 0)
{
if (j < 2)
arr[i - 1] = (j * 10) + arr[i - 1];
else if (j != 1)
strWord += " " + list[17 + j];
}
}
else
{
if (i == 2)
strWord += " " + list[j - 1] + " hundred ";
else if (i == 1)
{
if (j == 1)
arr[i - 1] = (j * 10) + arr[i - 1];
else if (j != 1)
strWord += " " + list[17 + j];
}
else if (i == 0)
strWord += " " + list[j - 1];
}
}
}
}
return (strWord + " Only");
}
//End of Method
Thursday, May 28, 2009
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment