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

Question:

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?

Solution:1

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

Solution:2

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);          }  ``

Solution:3

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

http://weblogs.asp.net/Justin_Rogers/archive/2004/06/09/151675.aspx

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

Solution:4

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:

Solution:5

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.

Solution:6

Nothing inbuilt. Here is a way to do this.

Solution:7

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
Previous
Next Post »