Click here to Skip to main content
12,953,700 members (48,239 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
how convert integer value to words:
eg: 1020=Thousand and twenty
Posted 3-Sep-12 20:54pm
Comments
Sourav Sarkar-SS 4-Sep-12 3:00am
   
I can give you all the code, but what have you tried?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

try this

Call
AmountInWords obj=new AmountInWords();
obj.Convert(10450.67)


AmountinWords.cs

class AmountInWords
   {
       private static String[] units = { "Zero", "One", "Two", "Three",
           "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven",
           "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen",
           "Seventeen", "Eighteen", "Nineteen" };
       private static String[] tens = { "", "", "Twenty", "Thirty", "Forty",
           "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };
 

       public String ConvertAmount(double amount)
       {
           try
           {
               int amount_int = (int)amount;
               int amount_dec = (int)Math.Round((amount - (double)(amount_int)) * 100);
               return  convert(amount_int) + "  point "
                       + convert(amount_dec) ;
           }
           catch (Exception e)
           {
               // TODO: handle exception
           }
           return "";
       }
 
       public String convert(int i)
       {
           //
           if (i < 20)
               return units[i];
           if (i < 100)
               return tens[i / 10] + ((i % 10 > 0) ? " " + convert(i % 10) : "");
           if (i < 1000)
               return units[i / 100] + " Hundred"
                       + ((i % 100 > 0) ? " and " + convert(i % 100) : "");
           if (i < 100000)
               return convert(i / 1000) + " Thousand "
                       + ((i % 1000 > 0) ? " " + convert(i % 1000) : "");
           if (i < 10000000)
               return convert(i / 100000) + " Lakh "
                       + ((i % 100000 > 0) ? " " + convert(i % 100000) : "");
           return convert(i / 10000000) + " Crore "
                   + ((i % 10000000 > 0) ? " " + convert(i % 10000000) : "");
       }
 
   }
  Permalink  
v2
Comments
amirmohamad 4-Sep-12 3:29am
   
vote 5+
Ganesh Nikam 4-Sep-12 4:22am
   
thanks
rajin.fortismail 8-Oct-12 2:47am
   
THANKS
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Take a look at this CP article
Convert numbers to words in English and Asian format[^]

Convert VB.net code to C# here[^]
  Permalink  
Comments
__TR__ 4-Sep-12 3:27am
   
Why downvoted ?
amirmohamad 4-Sep-12 3:38am
   
5+
__TR__ 4-Sep-12 3:48am
   
Thanks.
Mohamed Mitwalli 5-Sep-12 5:43am
   
5+
__TR__ 5-Sep-12 6:11am
   
Thanks Mohamed.
rajin.fortismail 8-Oct-12 2:48am
   
THANKS
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

I have written the program to convert currency to string.
little bit modifications to this program will do your work.

class Program
    {
        static void Main(string[] args)
        {
            string ammount=string .Empty ;
        Rep:
            Console.WriteLine("Enter the Ammount");
            ammount = Console.ReadLine();
            Regex r=new Regex (@"^[0-9]+(\.[0-9]+)?$");
            if (!r.IsMatch(ammount)|ammount .Length >9)
            {
                Console.Clear();
                Console.WriteLine("Enter Valid Number within Thousand Core\n");
                goto Rep;
            }
            string inWord = ConvertIntoCurrency(ammount.Trim());
            if (inWord == "Error")
            {
                Console.WriteLine("Enter Valid Number within Thousand Core\n");
                goto Rep;
            }
            Console.WriteLine("Ammount in words : "+inWord);
            Console.ReadLine();
        }
 

        //Function To Convert the Ammount
        static  string ConvertIntoCurrency(string ammount)
        {
            string inWords=string .Empty;
            int dec=0,cur,ix;
            cur = (int)double.Parse(ammount);
            string[] words = { ".Hundred.", ".Thousand.", ".Thousand.", ".Lakh.", ".Lakh.", ".Core.", ".Core." };
            int[] devidors = { 100, 1000, 1000, 100000, 100000, 10000000, 10000000 };
 
            if (ammount.IndexOf('.') > 0)
            {
                dec = int.Parse(ammount.Substring(ammount.IndexOf('.') + 1));
 
                if (dec >= 100)
                {
                    cur += dec / 100;
                    dec = dec % 100;
                }
            }
 
            if (cur == 0 & dec > 0)
                return dec.ToString() + ".Paise";
            if (cur == 0 & dec == 0)
                return "Nill";
            if (cur.ToString().Length > 9)
                return "Error";
 

           while (cur.ToString().Length > 2)
           {
               ix = cur.ToString().Length-3;
               inWords += (cur / devidors[ix]).ToString() + words[ix]+"And.";
               cur = cur % devidors[ix];
           }
 
           if (cur > 0)
           {
                inWords += cur.ToString();
           }
 
            if (inWords.LastIndexOf(".And.")==inWords .Length -5)
                inWords = inWords.Remove(inWords.Length - 5);
 
            if (cur == 1)
                inWords += ".Rupee";
            else
                inWords += ".Rupees";
 
            if (dec > 0)
                inWords += ".And." + dec.ToString() + ".Paise";
            return inWords;
        }
 
    }
  Permalink  
Comments
amirmohamad 4-Sep-12 3:29am
   
5+
rajin.fortismail 8-Oct-12 2:48am
   
THANKS
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

See this short post for C#. I briefly tested it and it works very well:
http://forums.exchangecore.com/topic/684-convert-number-to-words-c-console-application/[^]
You just need to copy the two functions to your code to use it:
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 % Math.Pow(10, power) > 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)
            {
               if (words != "" && tens == false)
                  words += " ";
               words += (tens ? "-" + numbersArr[(int)n - 1] : numbersArr[(int)n - 1]);
               n -= Math.Floor(n);
            }
         }
 
         return words;
 
      }
  Permalink  
Comments
rajin.fortismail 8-Oct-12 2:48am
   
THANKS

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
ppolymorphe 2,020
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100