Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
private void textWeight_TextChanged(object sender, EventArgs e)
        {
            try
            {

                //textWeight.Text = Double.Parse(textWeight.Text).ToString("N3");

                string s = "select Max(SrNo)+1 From TounchData";
                OleDbCommand csm = new OleDbCommand(s, connection);

                connection.Open();
                csm.ExecuteNonQuery();

                OleDbDataReader dd = csm.ExecuteReader();

                while (dd.Read())
                {
                    int n = dd.GetInt32(0);
                    textSrNo.Text = n.ToString();
                }


                connection.Close();
                //string NumericValue = textTounch.Text;
                //string getString = changeToWords(NumericValue);
                //LabelNoToWord.Text = getString;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex);
                //textTounch.Text = "";
                //LabelNoToWord.Text = "";
            }
            {
                LabelNoToWord.Text = "0";
            }
            if (textWeight.Text != "")
                LabelNoToWord.Text = (AmountInWords(Convert.ToInt32(textWeight.Text)));

        }


        public string AmountInWords(decimal Num)
        {
            string returnValue;
            //I have created this function for converting amount in indian rupees (INR).
            //You can manipulate as you wish like decimal setting, Doller (any currency) Prefix.


            string strNum;
            string strNumDec;
            string StrWord;
            strNum = Num.ToString();


            if (strNum.IndexOf(".") + 1 != 0)
            {
                strNumDec = strNum.Substring(strNum.IndexOf(".") + 2 - 1);


                if (strNumDec.Length == 1)
                {
                    strNumDec = strNumDec + "0";
                }
                if (strNumDec.Length > 2)
                {
                    strNumDec = strNumDec.Substring(0, 2);
                }


                strNum = strNum.Substring(0, strNum.IndexOf(".") + 0);
                StrWord = ((double.Parse(strNum) == 1) ? " Rupee " : " Rupees ") + NumToWord((decimal)(double.Parse(strNum))) + ((double.Parse(strNumDec) > 0) ? (" and Paise" + cWord3((decimal)(double.Parse(strNumDec)))) : "");
            }
            else
            {
                StrWord = ((double.Parse(strNum) == 1) ? " Rupee " : " Rupees ") + NumToWord((decimal)(double.Parse(strNum)));
            }
            returnValue = StrWord + " Only";
            return returnValue;
        }
        static public string NumToWord(decimal Num)
        {
            string returnValue;


            //I divided this function in two part.
            //1. Three or less digit number.
            //2. more than three digit number.
            string strNum;
            string StrWord;
            strNum = Num.ToString();


            if (strNum.Length <= 3)
            {
                StrWord = cWord3((decimal)(double.Parse(strNum)));
            }
            else
            {
                StrWord = cWordG3((decimal)(double.Parse(strNum.Substring(0, strNum.Length - 3)))) + " " + cWord3((decimal)(double.Parse(strNum.Substring(strNum.Length - 2 - 1))));
            }
            returnValue = StrWord;
            return returnValue;
        }
        static public string cWordG3(decimal Num)
        {
            string returnValue;
            //2. more than three digit number.
            string strNum = "";
            string StrWord = "";
            string readNum = "";
            strNum = Num.ToString();
            if (strNum.Length % 2 != 0)
            {
                readNum = System.Convert.ToString(double.Parse(strNum.Substring(0, 1)));
                if (readNum != "0")
                {
                    StrWord = retWord(decimal.Parse(readNum));
                    readNum = System.Convert.ToString(double.Parse("1" + strReplicate("0", strNum.Length - 1) + "000"));
                    StrWord = StrWord + " " + retWord(decimal.Parse(readNum));
                }
                strNum = strNum.Substring(1);
            }
            while (!System.Convert.ToBoolean(strNum.Length == 0))
            {
                readNum = System.Convert.ToString(double.Parse(strNum.Substring(0, 2)));
                if (readNum != "0")
                {
                    StrWord = StrWord + " " + cWord3(decimal.Parse(readNum));
                    readNum = System.Convert.ToString(double.Parse("1" + strReplicate("0", strNum.Length - 2) + "000"));
                    StrWord = StrWord + " " + retWord(decimal.Parse(readNum));
                }
                strNum = strNum.Substring(2);
            }
            returnValue = StrWord;
            return returnValue;
        }
        static public string cWord3(decimal Num)
        {
            string returnValue;
            //1. Three or less digit number.
            string strNum = "";
            string StrWord = "";
            string readNum = "";
            if (Num < 0)
            {
                Num = Num * -1;
            }
            strNum = Num.ToString();


            if (strNum.Length == 3)
            {
                readNum = System.Convert.ToString(double.Parse(strNum.Substring(0, 1)));
                StrWord = retWord(decimal.Parse(readNum)) + " Hundred";
                strNum = strNum.Substring(1, strNum.Length - 1);
            }


            if (strNum.Length <= 2)
            {
                if (double.Parse(strNum) >= 0 && double.Parse(strNum) <= 20)
                {
                    StrWord = StrWord + " " + retWord((decimal)(double.Parse(strNum)));
                }
                else
                {
                    StrWord = StrWord + " " + retWord((decimal)(System.Convert.ToDouble(strNum.Substring(0, 1) + "0"))) + " " + retWord((decimal)(double.Parse(strNum.Substring(1, 1))));
                }
            }


            strNum = Num.ToString();
            returnValue = StrWord;
            return returnValue;
        }
        static public string retWord(decimal Num)
        {
            string returnValue;
            //This two dimensional array store the primary word convertion of number.
            returnValue = "";
            object[,] ArrWordList = new object[,] { { 0, "" }, { 1, "One" }, { 2, "Two" }, { 3, "Three" }, { 4, "Four" }, { 5, "Five" }, { 6, "Six" }, { 7, "Seven" }, { 8, "Eight" }, { 9, "Nine" }, { 10, "Ten" }, { 11, "Eleven" }, { 12, "Twelve" }, { 13, "Thirteen" }, { 14, "Fourteen" }, { 15, "Fifteen" }, { 16, "Sixteen" }, { 17, "Seventeen" }, { 18, "Eighteen" }, { 19, "Nineteen" }, { 20, "Twenty" }, { 30, "Thirty" }, { 40, "Forty" }, { 50, "Fifty" }, { 60, "Sixty" }, { 70, "Seventy" }, { 80, "Eighty" }, { 90, "Ninety" }, { 100, "Hundred" }, { 1000, "Thousand" }, { 100000, "Lakh" }, { 10000000, "Crore" } };


            int i;
            for (i = 0; i <= (ArrWordList.Length - 1); i++)
            {
                if (Num == System.Convert.ToDecimal(ArrWordList[i, 0]))
                {
                    returnValue = (string)(ArrWordList[i, 1]);
                    break;
                }
            }
            return returnValue;
        }
        static public string strReplicate(string str, int intD)
        {
            string returnValue;
            //This fucntion padded "0" after the number to evaluate hundred, thousand and on....
            //using this function you can replicate any Charactor with given string.
            int i;
            returnValue = "";
            for (i = 1; i <= intD; i++)
            {
                returnValue = returnValue + str;
            }
            return returnValue;
        }


What I have tried:

I have created this function for converting amount in Indian Rupees (INR) so can you help me.
but i want to convert amount to rupees and paise in words format in c# oledb Server
Posted
Updated 13-Jul-17 22:06pm
v2
Comments
[no name] 25-Jun-16 11:34am    
Maybe you can Show "the relevant" part of your code and mark the parts you think the Problem is ... rather than post a bunch of code?

It will help us all...

Conver number into word[^]

how to convert number into words in C#[^]

It seems this is a perennial first year class assignment. And then all the students are so proud of their creations that they post them here.

Similarly, please consider that teachers know about this site and will know if you simply copied (plagiarized) any of these implementations.
Furthermore, none of these implementations is perfect, but you can read each and use the concepts you like to form a solution that is truly your own.


We have so many we even have a spoof: Converting numbers to the word equivalent. [^]

How to Convert Numeric Value to Text(String)[^]

Convert Currency To Words in Lakh, Crores, etc.[^]

Convert Amount in Words and Separate Amount with comma in Bangladeshi Currency Format using C#.NET[^]

XSLT Number to String Transformation II[^]

Convert Numeric Currency into Words for International Currency - Part - II (Optimized)[^]


Converting numbers into English[^]

How to Convert a Numeric Value or Currency to English Words Using C#[^]

Convert Number to Text[^]

Number To Word (Arabic Version)[^]

http://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=156342&aid=867081[^]
 
Share this answer
 
Comments
Member 12556431 27-Jun-16 7:00am    
I have created this function for converting amount in Indian Rupees and paise (INR) so can you help me.
hey you need solution your email address , i will send the whole code with library.

C#
private void button2_Click(object sender, EventArgs e)
        {
            GenerateWordsinRs();

        }

        private void GenerateWordsinRs()
        {
            decimal numberrs = Convert.ToDecimal(txtNumber.Text);
            CultureInfo ci = new CultureInfo("en-IN");
            string aaa = String.Format("{0:#,##0.##}", numberrs);
            aaa = aaa + " " + ci.NumberFormat.CurrencySymbol.ToString();
            label6.Text = aaa;


            string input = txtNumber.Text;
            string a = "";
            string b = "";

            // take decimal part of input. convert it to word. add it at the end of method.
            string decimals = "";

            if (input.Contains("."))
            {
                decimals = input.Substring(input.IndexOf(".") + 1);
                // remove decimal part from input
                input = input.Remove(input.IndexOf("."));

            }
            string strWords = NUMBERTOWORDS.NumbersToWords(Convert.ToInt32(input));

            if (!txtNumber.Text.Contains("."))
            {
                a = strWords + " Rupees Only";
            }
            else
            {
                a = strWords + " Rupees";
            }

            if (decimals.Length > 0)
            {
                // if there is any decimal part convert it to words and add it to strWords.
                string strwords2 = NUMBERTOWORDS.NumbersToWords(Convert.ToInt32(decimals));
                b = " and " + strwords2 + " Paisa Only ";
            }

            label7.Text = a + b;
        }   
//NUMBERTOWORDS.NumbersToWords(Convert.ToInt32(input)); //NUMBERTOWORDS IS A CLASS

//NUMBERTOWORDS CLASS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace rounfoffmath
{
    class NUMBERSTOWORDS
    {
        public static string NumbersToWords(int inputNumber)
        {
            int inputNo = inputNumber;

            if (inputNo == 0)
                return "Zero";

            int[] numbers = new int[4];
            int first = 0;
            int u, h, t;
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            if (inputNo < 0)
            {
                sb.Append("Minus ");
                inputNo = -inputNo;
            }

            string[] words0 = {"" ,"One ", "Two ", "Three ", "Four ",
            "Five " ,"Six ", "Seven ", "Eight ", "Nine "};
            string[] words1 = {"Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ",
            "Fifteen ","Sixteen ","Seventeen ","Eighteen ", "Nineteen "};
            string[] words2 = {"Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ",
            "Seventy ","Eighty ", "Ninety "};
            string[] words3 = { "Thousand ", "Lakh ", "Crore " };

            numbers[0] = inputNo % 1000; // units
            numbers[1] = inputNo / 1000;
            numbers[2] = inputNo / 100000;
            numbers[1] = numbers[1] - 100 * numbers[2]; // thousands
            numbers[3] = inputNo / 10000000; // crores
            numbers[2] = numbers[2] - 100 * numbers[3]; // lakhs

            for (int i = 3; i > 0; i--)
            {
                if (numbers[i] != 0)
                {
                    first = i;
                    break;
                }
            }
            for (int i = first; i >= 0; i--)
            {
                if (numbers[i] == 0) continue;
                u = numbers[i] % 10; // ones
                t = numbers[i] / 10;
                h = numbers[i] / 100; // hundreds
                t = t - 10 * h; // tens
                if (h > 0) sb.Append(words0[h] + "Hundred ");
                if (u > 0 || t > 0)
                {
                    if (h > 0 || i == 0) sb.Append("");
                    if (t == 0)
                        sb.Append(words0[u]);
                    else if (t == 1)
                        sb.Append(words1[u]);
                    else
                        sb.Append(words2[t - 2] + words0[u]);
                }
                if (i != 0) sb.Append(words3[i - 1]);
            }
            return sb.ToString().TrimEnd();
        }
    }
}
// enJOY tHIS code, have fun, try it to convert amount into indian currency and words into indian formats. :) developed by shaan
 
Share this answer
 
v5
I found that,
Calling two functions can convert decimal amount like 123.12 number to word rupees and paise.


this is the code for conversion

give any value to amount and it will convert


C#
public conversion(string amount)
        {
double m = Convert.ToInt64(Math.Floor(Convert.ToDouble(amount)));
            double l = Convert.ToDouble(amount);
            
            double j = ( l - m ) * 100;
           

            var beforefloating = ConvertNumbertoWords(Convert.ToInt64(m));
            var afterfloating = ConvertNumbertoWords(Convert.ToInt64(j));



            var Content = beforefloating + ' ' + " RUPEES" + ' ' + afterfloating + ' ' + " PAISE only";

}




main code of this Program

C#
public string ConvertNumbertoWords(long number)
     {
         if (number == 0) return "ZERO";
         if (number < 0) return "minus " + ConvertNumbertoWords(Math.Abs(number));
         string words = "";
         if ((number / 1000000) > 0)
         {
             words += ConvertNumbertoWords(number / 100000) + " LAKES ";
             number %= 1000000;
         }
         if ((number / 1000) > 0)
         {
             words += ConvertNumbertoWords(number / 1000) + " THOUSAND ";
             number %= 1000;
         }
         if ((number / 100) > 0)
         {
             words += ConvertNumbertoWords(number / 100) + " HUNDRED ";
             number %= 100;
         }
         //if ((number / 10) > 0)  
         //{  
         // words += ConvertNumbertoWords(number / 10) + " RUPEES ";  
         // number %= 10;  
         //}  
         if (number > 0)
         {
             if (words != "") words += "AND ";
             var unitsMap = new[]   
        {  
            "ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN"  
        };
             var tensMap = new[]   
        {  
            "ZERO", "TEN", "TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY"  
        };
             if (number < 20) words += unitsMap[number];
             else
             {
                 words += tensMap[number / 10];
                 if ((number % 10) > 0) words += " " + unitsMap[number % 10];
             }
         }
         return words;
     }



like this two time calling the same function can generate words for decimal numbers
 
Share this answer
 
Comments
Richard Deeming 22-Jun-17 15:33pm    
This question was posted almost exactly one year ago, and already has a perfectly reasonable solution.
AkashBabu 18-Jul-17 2:34am    
i tried that that solution ,it didn't work exactly and now i have posted the above codes for simple understanding

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900