I searched for something like this existing already, failing to find

it, I wrote it myself. If this already existed somewhere in the

framework I appologize for my ignorance.

This method will take any number within the bounds of an int

(int.MinValue - int.MaxValue) inclusive and converts it to an english

number.

For example, it will take "1" and give you "one", "2" yields "two",

"-475918" give you a whopping "negative four hundred seventy five

thousand nine hundred eighteen"

It can also do what I called "positional numbering" for example given

32, with positional boolean set to true, it will return "thirty

second"

so "1" gives "first"

"2" gives "second", etc...

The method is static, as well as it's support array, so just dump them

into a class anywhere.

/// <summary>

/// A matrix of the oddities in the English counting system

/// such as five -> fifth, and all those strange teens

/// </summary>

protected static string[][] _englishDigitMa trix = new string[][]

{

new string[] {"zero", "zeroth", ""},

new string[] {"one", "first", ""},

new string[] {"two", "second", "twenty"},

new string[] {"three", "third", "thirty"},

new string[] {"four", "fourth", "fourty"},

new string[] {"five", "fifth", "fifty"},

new string[] {"six", "sixth", "sixty"},

new string[] {"seven", "seventh", "seventy"},

new string[] {"eight", "eighth", "eighty"},

new string[] {"nine", "nineth", "ninety"},

new string[] {"ten", "", ""},

new string[] {"eleven", "", ""},

new string[] {"twelve", "", ""},

new string[] {"thirteen", "", ""},

new string[] {"fourteen", "", ""},

new string[] {"fifteen", "", ""},

new string[] {"sixteen", "", ""},

new string[] {"seventeen" , "", ""},

new string[] {"eighteen", "", ""},

new string[] {"nineteen", "", ""}

};

/// <summary>

/// Converts an integer, within the Max and Min valuse for an int

(inclusive)

/// into English words. The conversion can also use numerical order

positions

/// such as "first" "second", "thirty third" by setting the bool

/// Written by Andrew Arace 10/2004

/// </summary>

/// <param name="number">a ny integer, positive or negative, within the

bounds of int.</param>

/// <param name="place">tr ue to set to ordered positions, such as

"second" instead of "two"</param>

/// <returns>englis h string</returns>

protected static string NumberToEnglish (int number, bool order) {

string returnString = string.Empty;

int tempNumber = number;

int countPlace = 0;

int sign = 1;

bool teen = false;

bool single = false;

bool tens = false;

if(number < 0) {

sign *= -1;

returnString += "negative ";

}

//count the billions (int max is over two billion)

countPlace = (tempNumber / 1000000000) * sign;

if(countPlace > 0) {

returnString += NumberToEnglish (countPlace, false) + " billion

";

}

tempNumber -= (1000000000 * countPlace) * sign;

//count the millions

countPlace = (tempNumber / 1000000) * sign;

if(countPlace > 0) {

returnString += NumberToEnglish (countPlace, false) + " million

";

}

tempNumber -= (1000000 * countPlace) * sign;

//count the thousands

countPlace = (tempNumber / 1000) * sign;

if(countPlace > 0) {

returnString += NumberToEnglish (countPlace, false) + "

thousand ";

}

tempNumber -= (1000 * countPlace) * sign;

//any recursion falls in here - in english, the main number

//groupings are in the hundreds - hundreds, hundreds of thousands

//hundreds of millions, etc.

countPlace = (tempNumber / 100) * sign;

if(countPlace > 0) {

returnString += _englishDigitMa trix[countPlace][0] + " hundred

";

}

tempNumber -= (100 * countPlace) * sign;

//count the 10's places

countPlace = (tempNumber / 10) * sign;

if(countPlace > 0) {

tens = true;

if(countPlace == 1) {

teen = true;

}

else {

returnString += _englishDigitMa trix[countPlace][2] + " ";

}

}

tempNumber -= (10 * countPlace) * sign;

//when working with single digits, and also

//teens, the rules change a bit.

tempNumber *= sign; //for the singles, read positives

if(tempNumber >= 0) {

//catch if we have any single digits

if(tempNumber == 0) {

single = false;

}

else {

single = true;

}

//catch the teens, and the number ten as well

if(teen) {

returnString += _englishDigitMa trix[10 + tempNumber][0];

//catch the position order

if(order) {

returnString += "th";

}

}

else if (tempNumber > 0) {

//catch the position order for single digits

if(order) {

returnString += _englishDigitMa trix[tempNumber][1];

}

else {

returnString += _englishDigitMa trix[tempNumber][0];

}

}

else if (tempNumber == 0 && returnString.Le ngth == 0) {

//need to catch the solitary number 0

//nothing will have been caught before this,

//so returnString will be empty.

if(order) {

returnString += _englishDigitMa trix[tempNumber][1];

}

else {

returnString += _englishDigitMa trix[tempNumber][0];

}

}

}

returnString = returnString.Tr im();

//check if it ended on a signifier greater than or

//equal to the hundreds - it won't have any order

//qualifiers, we need to add them

if(order) {

if(returnString .EndsWith("bill ion") ||

returnString.En dsWith("million ") ||

returnString.En dsWith("thousan d") ||

returnString.En dsWith("hundred ")) {

returnString += "th";

}

else if(!single && !teen && tens) {

//must be multiple of 10, greater than or equal to 20

//less than onehundred

returnString = returnString.Su bstring(0,

returnString.Le ngth-1) + "ieth";

}

}

return returnString;

}

-Andrew Arace