Tutorial :Convert an Integer to a string of words [duplicate]


Possible Duplicate:
C# Convert Integers into Written Numbers

I need to take an integer value and convert it to its english word equivalent (i.e. 4 => "four", 1879 => "one thousand, eight hundred seventy-nine") in .NET (3.5 to be specific).

I'm wondering if there is anything built into the .NET framework for making such a conversion. Seems like it would be useful enough to belong there. I haven't been able to find anything to do the job.

If it isn't included in the framework anywhere, does anyone have any ideas more elegant than a digit/place specific lookup?


Check out this link: Functional Fun: Euler 17 for a LINQ solution.


string s being the input number

      const string input = "1023";            string[] placement = { "thousand", "hundred", "ten", "" };          string[] numbersToLetters = { "", "one", "two", "tre", "four", "five", "six", "seven", "eight", "nine" };            for (int i = 0; i < input.Length; i++)          {              int  digits = input[i] != '0' ? (placement.Length - input.Length) + i : 3;              int result = int.Parse(input[i].ToString());                var type = placement[digits];              var number = numbersToLetters[result];              Console.WriteLine(number + type);          }  


This looks to do the trick, so long as you aren't going to be dealing with anything past the trillions.


edit: here is a working link to something similar https://www.exchangecore.com/blog/convert-number-words-c-sharp-console-application/


There isn't anything built in that I'm aware of. You're just going to have to do some digit-parsing and replacing.

I did find some examples on the net:

http://www.dotnetspider.com/resources/2743-Code-Convert-numbers-word.aspx http://www.codeproject.com/KB/cs/codesamples.aspx


There is no direct function to convert and create word forms for you. You will have to write your program, where essentially you will have to hardcode values of all digits i.e. 1 one,2 two,...,9 nine. Then also you will have to take care of tens, hundreds, thousands, and then you will have to write logic to extract digits and append the words accordingly.


Nothing inbuilt. Here is a way to do this.


Not built in, but this is what I use: .NET convert number to string representation (1 to one, 2 to two, etc...)

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »