Convert a number between 0 and 999 into words.Next if the number is greater than 99, the function gets the hundreds digit and uses the one_to_nineteen array to look up its string representation.Empty, 0 / summary / / /summary / param name"value" input string number /param / param name"language" local language /param / public static string NumberToText(this string value, Language language) int number; if (yParse(value, out number) return NumberToText(rse(value language throw new FormatException Input string is not correct format.For example, with the value 123,456, dividing by 1000 and truncating gives 123.If the number is 0, the method returns zero.Group_num; / Remove the trailing ".Digit (int num / 10 num num 10; result " " multiples_of_tendigit - 2; / Handle the final digit.If (num 20) / Look up the correct name.English, Names new List string "Twenty "Thirty "Forty "Fifty "Sixty "Seventy "Eighty "Ninety",new NumberWord Group DigitGroup. Private Methods (2) / summary / / /summary / param name"idx" /param / param / param name"group" /param / private static string GetName(int idx, Language language, DigitGroup group) return rst(x oup group nguage language).Namesidx; / summary / / /summary / param name"number" /param / param / param / param / private static string Wordify(long number, Language language, string leftDigitsText, int thousands) / if (number 0) return leftDigitsText; / var wordValue leftDigitsText; / if (wordValue.
Teens, Language rsian, Names new List string "?
This example builds the ToWords extension method to convert numbers into words.
English, "Negative ", rsian, "? .
"?", new NumberWord Group ndreds, Language Language.
After you build your map, you need to work through each digit in your number and figure out the appropriate nomenclature to go with.
Int group_num 0; while (num 0) / Get the next group of three digits.Do you mean "words" or "strings"?If the number has no other digits, the function returns what it has so far.If (num 0) return "zero string groups "thousand "million "billion "trillion "quadrillion "?The following code shows the extension method.Result " " one_to_nineteennum; else / Handle the tens digit.For example, the following might represent a few entries in the dictionary: 1, "one" 2, "two" 30, "thirty you really only need to worry about mapping numbers in the 100 (1,2,3, etc.) and 101 (10,20,30) positions because once you get to 100, you simply have.However, if you need to convert123intoone hundred twenty three, then you need to do more parsing.If (num 0) result " " one_to_nineteennum; return im The GroupToWords method starts by defining names for values between 0 and 19, and for multiples.If (num 0) return im / See if the rest is less than.Finally the method uses the one_to_nineteen array to add on the representation of the ones digit.