Click here to Skip to main content
16,021,125 members

Comments by Member 12556431 (Top 9 by date)

Member 12556431 5-Jul-16 4:03am View    
if (textAmount.Text != "")
LabelNoToWord.Text = (changeNumericToWords(Convert.ToInt32(textAmount.Text)));

static String NumWordsWrapper(double n)
{
string words = "";
double intPart;
double decPart = 0;
if (n == 0)
return "zero";
try {
string[] splitter = n.ToString().Split('.');
intPart = double.Parse(splitter[0]);
decPart = double.Parse(splitter[1]);
} catch {
intPart = n;
}

words = NumWords(intPart);

if (decPart > 0) {
if (words != "")
words += " and ";
int counter = decPart.ToString().Length;
switch (counter) {
case 1: words += NumWords(decPart) + " tenths"; break;
case 2: words += NumWords(decPart) + " hundredths"; break;
case 3: words += NumWords(decPart) + " thousandths"; break;
case 4: words += NumWords(decPart) + " ten-thousandths"; break;
case 5: words += NumWords(decPart) + " hundred-thousandths"; break;
case 6: words += NumWords(decPart) + " millionths"; break;
case 7: words += NumWords(decPart) + " ten-millionths"; break;
}
}
return words;
}

static String NumWords(double n) //converts double to words
{
string[] numbersArr = new string[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
string[] tensArr = new string[] { "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninty" };
string[] suffixesArr = new string[] { "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion", "septillion", "octillion", "nonillion", "decillion", "undecillion", "duodecillion", "tredecillion", "Quattuordecillion", "Quindecillion", "Sexdecillion", "Septdecillion", "Octodecillion", "Novemdecillion", "Vigintillion" };
string words = "";

bool tens = false;

if (n < 0) {
words += "negative ";
n *= -1;
}

int power = (suffixesArr.Length + 1) * 3;

while (power > 3) {
double pow = Math.Pow(10, power);
if (n >= pow) {
if (n % pow > 0) {
words += NumWords(Math.Floor(n / pow)) + " " + suffixesArr[(power / 3) - 1] + ", ";
} else if (n % pow == 0) {
words += NumWords(Math.Floor(n / pow)) + " " + suffixesArr[(power / 3) - 1];
}
n %= pow;
}
power -= 3;
}
if (n >= 1000) {
if (n % 1000 > 0) words += NumWords(Math.Floor(n / 1000)) + " thousand, ";
else words += NumWords(Math.Floor(n / 1000)) + " thousand";
n %= 1000;
}
if (0 <= n && n <= 999) {
if ((int)n / 100 > 0) {
words += NumWords(Math.Floor(n / 100)) + " hundred";
n %= 100;
}
if ((int)n / 10 > 1) {
if (words != "")
words += " ";
words += tensArr[(int)n / 10 - 2];
tens = true;
n %= 10;
}

if (n < 20 && n > 0) {
if (words != "" && tens == false)
words += " ";
words += (tens ? "-" + numbersArr[(int)n - 1] : numbersArr[(int)n - 1]);
n -= Math.Floor(n);
}
Member 12556431 5-Jul-16 3:59am View    
Deleted
if (textAmount.Text != "")
LabelNoToWord.Text = (changeNumericToWords(Convert.ToInt32(textAmount.Text)));

static String NumWordsWrapper(double n)
{
string words = "";
double intPart;
double decPart = 0;
if (n == 0)
return "zero";
try {
string[] splitter = n.ToString().Split('.');
intPart = double.Parse(splitter[0]);
decPart = double.Parse(splitter[1]);
} catch {
intPart = n;
}

words = NumWords(intPart);

if (decPart > 0) {
if (words != "")
words += " and ";
int counter = decPart.ToString().Length;
switch (counter) {
case 1: words += NumWords(decPart) + " tenths"; break;
case 2: words += NumWords(decPart) + " hundredths"; break;
case 3: words += NumWords(decPart) + " thousandths"; break;
case 4: words += NumWords(decPart) + " ten-thousandths"; break;
case 5: words += NumWords(decPart) + " hundred-thousandths"; break;
case 6: words += NumWords(decPart) + " millionths"; break;
case 7: words += NumWords(decPart) + " ten-millionths"; break;
}
}
return words;
}

static String NumWords(double n) //converts double to words
{
string[] numbersArr = new string[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
string[] tensArr = new string[] { "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninty" };
string[] suffixesArr = new string[] { "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion", "septillion", "octillion", "nonillion", "decillion", "undecillion", "duodecillion", "tredecillion", "Quattuordecillion", "Quindecillion", "Sexdecillion", "Septdecillion", "Octodecillion", "Novemdecillion", "Vigintillion" };
string words = "";

bool tens = false;

if (n < 0) {
words += "negative ";
n *= -1;
}

int power = (suffixesArr.Length + 1) * 3;

while (power > 3) {
double pow = Math.Pow(10, power);
if (n >= pow) {
if (n % pow > 0) {
words += NumWords(Math.Floor(n / pow)) + " " + suffixesArr[(power / 3) - 1] + ", ";
} else if (n % pow == 0) {
words += NumWords(Math.Floor(n / pow)) + " " + suffixesArr[(power / 3) - 1];
}
n %= pow;
}
power -= 3;
}
if (n >= 1000) {
if (n % 1000 > 0) words += NumWords(Math.Floor(n / 1000)) + " thousand, ";
else words += NumWords(Math.Floor(n / 1000)) + " thousand";
n %= 1000;
}
if (0 <= n && n <= 999) {
if ((int)n / 100 > 0) {
words += NumWords(Math.Floor(n / 100)) + " hundred";
n %= 100;
}
if ((int)n / 10 > 1) {
if (words != "")
words += " ";
words += tensArr[(int)n / 10 - 2];
tens = true;
n %= 10;
}

if (n < 20 && n > 0) {
if (words != "" && tens == false)
words += " ";
words += (tens ? "-" + numbersArr[(int)n - 1] : numbersArr[(int)n - 1]);
n -= Math.Floor(n);
}
}

return words;

}
sta
Member 12556431 28-Jun-16 8:47am View    
im making a code but if i inter dot then program is stop working and error
Member 12556431 28-Jun-16 8:40am View    
Sir can you help me for convert number to words in indian rupees in Rupee and Paise like 1110.56 c#
in word like, One Thousand One Hundred Ten Rupees And Fifty Six Paise.
Member 12556431 28-Jun-16 3:10am View    
Thank you Jayanta Chatterjee Sir it is work for me, lots of thanks to you sir.