<p>Here's a coding problem for those that like this kind of thing. Let's see your implementations (in your language of choice, of course) of a function which returns a human readable String representation of a specified Integer. For example:</p>

<ul>
<li>humanReadable(1) returns "one".
<li>humanReadable(53) returns "fifty-three".
<li>humanReadable(723603) returns "seven hundred and twenty-three thousand, six hundred and three".
<li>humanReadable(1456376562) returns "one billion, four hundred and fifty-six million, three hundred and seventy-six thousand, five hundred and sixty-two".
</ul>

<p>Bonus points for particularly clever/elegant solutions!</p>

<p>It might seem like a pointless exercise, but there are number of real world applications for this kind of algorithm (although supporting numbers as high as a billion may be overkill :-)</p>

[{'answer_id': 11413, 'author': 'mbillard', 'author_id': 810, 'author_profile': 'https://Stackoverflow.com/users/810', 'pm_score': 4, 'selected': True, 'text': '<p>There was already a question about this:\n<a href="https://stackoverflow.com/questions/3213/c-convert-integers-into-written-numbers">Convert integers to written numbers</a></p>\n\n<p>The answer is for C#, but I think you can figure it out.</p>\n'}, {'answer_id': 11415, 'author': 'Ryan Ahearn', 'author_id': 75, 'author_profile': 'https://Stackoverflow.com/users/75', 'pm_score': 1, 'selected': False, 'text': '<p>Supports up to 999 million, but no negative numbers:</p>\n\n<pre><code>String humanReadable(int inputNumber) {\n  if (inputNumber == -1) {\n    return "";\n  }\n  int remainder;\n  int quotient;\n  quotient = inputNumber / 1000000;\n  remainder = inputNumber % 1000000;\n  if (quotient &gt; 0) {\n    return humanReadable(quotient) + " million, " + humanReadable(remainder);\n  }\n  quotient = inputNumber / 1000;\n  remainder = inputNumber % 1000;\n  if (quotient &gt; 0) {\n    return humanReadable(quotient) + " thousand, " + humanReadable(remainder);\n  }\n  quotient = inputNumber / 100;\n  remainder = inputNumber % 100;\n  if (quotient &gt; 0) {\n    return humanReadable(quotient) + " hundred, " + humanReadable(remainder);\n  }\n  quotient = inputNumber / 10;\n  remainder = inputNumber % 10;\n  if (remainder == 0) {\n    //hackish way to flag the algorithm to not output something like "twenty zero"\n    remainder = -1;\n  }\n  if (quotient == 1) {\n    switch(inputNumber) {\n    case 10:\n      return "ten";\n    case 11:\n      return "eleven";\n    case 12:\n      return "twelve";\n    case 13:\n      return "thirteen";\n    case 14:\n      return "fourteen";\n    case 15:\n      return "fifteen";\n    case 16:\n      return "sixteen";\n    case 17:\n      return "seventeen";\n    case 18:\n      return "eighteen";\n    case 19:\n      return "nineteen";\n    }\n  }\n  switch(quotient) {\n  case 2:\n    return "twenty " + humanReadable(remainder);\n  case 3:\n    return "thirty " + humanReadable(remainder);\n  case 4:\n    return "forty " + humanReadable(remainder);\n  case 5:\n    return "fifty " + humanReadable(remainder);\n  case 6:\n    return "sixty " + humanReadable(remainder);\n  case 7:\n    return "seventy " + humanReadable(remainder);\n  case 8:\n    return "eighty " + humanReadable(remainder);\n  case 9:\n    return "ninety " + humanReadable(remainder);\n  }\n  switch(inputNumber) {\n  case 0:\n    return "zero";\n  case 1:\n    return "one";\n  case 2:\n    return "two";\n  case 3:\n    return "three";\n  case 4:\n    return "four";\n  case 5:\n    return "five";\n  case 6:\n    return "six";\n  case 7:\n    return "seven";\n  case 8:\n    return "eight";\n  case 9:\n    return "nine";\n  }\n}\n</code></pre>\n'}, {'answer_id': 11417, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': "<pre><code>import math\n\ndef encodeOnesDigit(num):\n   return ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'][num]\n\ndef encodeTensDigit(num):\n   return ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'][num-2]\n\ndef encodeTeens(num):\n   if num &lt; 10:\n      return encodeOnesDigit(num)\n   else:\n      return ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'][num-10]\n\ndef encodeTriplet(num):\n   if num == 0: return ''\n   str = ''\n   if num &gt;= 100:\n      str = encodeOnesDigit(num / 100) + ' hundred'\n   tens = num % 100\n   if tens &gt;= 20:\n      if str != '': str += ' '\n      str += encodeTensDigit(tens / 10)\n      if tens % 10 &gt; 0:\n         str += '-' + encodeOnesDigit(tens % 10)\n   elif tens != 0:\n      if str != '': str += ' '\n      str += encodeTeens(tens)\n   return str\n\ndef zipNumbers(numList):\n   if len(numList) == 1:\n      return numList[0]\n   strList = ['', ' thousand', ' million', ' billion'] # Add more as needed\n   strList = strList[:len(numList)]\n   strList.reverse()\n   joinedList = zip(numList, strList)\n   joinedList = [item for item in joinedList if item[0] != '']\n   return ', '.join(''.join(item) for item in joinedList)\n\ndef humanReadable(num):\n   if num == 0: return 'zero'\n   negative = False\n   if num &lt; 0:\n      num *= -1\n      negative = True\n   numString = str(num)\n   tripletCount = int(math.ceil(len(numString) / 3.0))\n   numString = numString.zfill(tripletCount * 3)\n   tripletList = [int(numString[i*3:i*3+3]) for i in range(tripletCount)]\n   readableList = [encodeTriplet(num) for num in tripletList]\n   readableStr = zipNumbers(readableList)\n   return 'negative ' + readableStr if negative else readableStr\n</code></pre>\n"}, {'answer_id': 11444, 'author': 'Stu', 'author_id': 414, 'author_profile': 'https://Stackoverflow.com/users/414', 'pm_score': 1, 'selected': False, 'text': '<pre><code>using System;\n\nnamespace HumanReadable\n{\n    public static class HumanReadableExt\n    {\n        private static readonly string[] _digits = {\n                                                       "", "one", "two", "three", "four", "five",\n                                                       "six", "seven", "eight", "nine", "eleven", "twelve",\n                                                       "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",\n                                                       "eighteen", "nineteen"\n                                                   };\n\n        private static readonly string[] _teens = {\n                                                      "", "", "twenty", "thirty", "forty", "fifty",\n                                                      "sixty", "seventy", "eighty", "ninety"\n                                                  };\n\n        private static readonly string[] _illions = {\n                                                        "", "thousand", "million", "billion", "trillion"\n                                                    };\n\n        private static string Seg(int number)\n        {\n            var work = string.Empty;\n\n            if (number &gt;= 100) \n                work += _digits[number / 100] + " hundred ";\n\n            if ((number % 100) &lt; 20)\n                work += _digits[number % 100];\n            else\n                work += _teens[(number % 100) / 10] + "-" + _digits[number % 10];\n\n            return work;\n        }\n\n        public static string HumanReadable(this int number)\n        {\n            if (number == 0)\n                return "zero";\n            var work = string.Empty;\n\n            var parts = new string[_illions.Length];\n\n            for (var ind = 0; ind &lt; parts.Length; ind++)\n                parts[ind] = Seg((int) (number % Math.Pow(1000, ind + 1) / Math.Pow(1000, ind)));\n\n            for (var ind = 0; ind &lt; parts.Length; ind++)\n                if (!string.IsNullOrEmpty(parts[ind]))\n                    work = parts[ind] + " " + _illions[ind] + ", " + work;\n\n            work = work.TrimEnd(\',\', \' \');\n\n            var lastSpace = work.LastIndexOf(\' \');\n            if (lastSpace &gt;= 0)\n                work = work.Substring(0, lastSpace) + " and" + work.Substring(lastSpace);\n\n            return work;\n        }\n    }\n\n    class Program\n    {\n\n        static void Main(string[] args)\n        {\n            Console.WriteLine(1.HumanReadable());\n            Console.WriteLine(53.HumanReadable());\n            Console.WriteLine(723603.HumanReadable());\n            Console.WriteLine(1456376562.HumanReadable());\n            Console.ReadLine();\n        }\n    }\n}\n</code></pre>\n'}, {'answer_id': 201121, 'author': 'akalenuk', 'author_id': 25459, 'author_profile': 'https://Stackoverflow.com/users/25459', 'pm_score': 0, 'selected': False, 'text': "<p>There's one huge problem about this function implementation. It is it's future localization. That function, written by english native speaker, most probably wouldn't work right for any other language than english. It is nearly impossible to write general easy localizable function for any human language dialect in a world, unless you really need to keep it general. Actually in real world you do not need to operate with huge integer numbers, so you can just keep all the numbers in a big (or even not so big) string array. </p>\n"}, {'answer_id': 214352, 'author': 'mat kelcey', 'author_id': 26094, 'author_profile': 'https://Stackoverflow.com/users/26094', 'pm_score': 0, 'selected': False, 'text': "<p>agreed that there are a number of real world applications.\nas such there's already a number of real world implementations.</p>\n\n<p>it's been part of bsdgames since pretty much forever...</p>\n\n<pre><code>&gt; man number\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/11381', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1030/']