{"id":5794,"date":"2015-01-09T09:00:08","date_gmt":"2015-01-09T14:00:08","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=5794"},"modified":"2015-01-07T04:30:20","modified_gmt":"2015-01-07T09:30:20","slug":"spelling-out-numbers","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2015\/01\/09\/spelling-out-numbers\/","title":{"rendered":"Spelling out numbers"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\">Jiro<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/47221-number-to-words\"><tt>num2words<\/tt><\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/186085\">Stephen Cobeldick<\/a>.\r\n   <\/p>\r\n   <p>Just recently, I witnessed a typo on a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Cheque\">check<\/a> payment. The amount was for \"$19050\" (unfortunately, it wasn't for me) but the written text read \"One thousand nine hundred\r\n      fifty dollars\". Many people might wonder why someone would make such a simple mistake. Did the person miscount the number\r\n      of zeroes?\r\n   <\/p>\r\n   <p>I think I have an idea. This was written in Japan. In Japan, and in many other Asian countries, <a href=\"http:\/\/en.wikipedia.org\/wiki\/Japanese_numerals#Large_numbers\">large numbers<\/a> are grouped in myriads (every 10000). <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_numbertowords\/potw_numbertowords_eq14079313239914964384.png\">  is called <i>man<\/i> (&#19975;), <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_numbertowords\/potw_numbertowords_eq12513619863904473246.png\">  is called <i>oku<\/i> (&#20740;), <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_numbertowords\/potw_numbertowords_eq12336315421045451032.png\">  is called <i>cho<\/i> (&#20806;). However in Western counting, large numbers are grouped in 1000s - thousand, million, billion, trillion, etc. So, it's\r\n      likely that the person writing the check wrote \"19050\", read it as \"1 <i>man<\/i> 9050\", and incorrectly translated to \"1 thousand 9 hundred 50\". Maybe...\r\n   <\/p>\r\n   <p>Anyway, all of this could have been avoided if this person had access to Stephen's <tt>num2words<\/tt>! Just let his function spell out the number in words.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">num2words(19050)<\/pre><pre style=\"font-style:oblique\">ans =\r\nnineteen thousand and fifty\r\n<\/pre><p>This is the simplest use case, but <tt>num2words<\/tt> comes with a wealth of options to customize how the results are returned.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">num2words(19050,<span style=\"color: #A020F0\">'type'<\/span>,<span style=\"color: #A020F0\">'cheque'<\/span>)<\/pre><pre style=\"font-style:oblique\">ans =\r\nnineteen thousand and fifty dollars only\r\n<\/pre><p>Stephen includes a detailed help in the function, so you can learn about all the options just by typing<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">help <span style=\"color: #A020F0\">num2words<\/span><\/pre><p>What gave me a little chuckle was that when I looked inside his function, I could see that he made sure that his function\r\n      can count up to <i>Uncentillion<\/i> which is <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_numbertowords\/potw_numbertowords_eq11949194457586414448.png\"> . So if you need to spell out a number larger than <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_numbertowords\/potw_numbertowords_eq09538913828594673286.png\"> , you might be out of luck. :)\r\n   <\/p>\r\n   <p><b>Comments<\/b><\/p>\r\n   <p>Give this a try, and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=5794#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/47221-number-to-words#comments\">comment<\/a> for Stephen.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_a594f68b23c34d28866f46c3d2b56a95() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='a594f68b23c34d28866f46c3d2b56a95 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' a594f68b23c34d28866f46c3d2b56a95';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = '';\r\n        copyright = 'Copyright 2015 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_a594f68b23c34d28866f46c3d2b56a95()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2014b<br><\/p>\r\n<\/div>\r\n<!--\r\na594f68b23c34d28866f46c3d2b56a95 ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\r\n% Jiro>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/47221-number-to-words |num2words|>\r\n% by <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/186085\r\n% Stephen Cobeldick>.\r\n%\r\n% Just recently, I witnessed a typo on a\r\n% <http:\/\/en.wikipedia.org\/wiki\/Cheque check> payment. The amount was for\r\n% \"$19050\" (unfortunately, it wasn't for me) but the written text read \"One\r\n% thousand nine hundred fifty dollars\". Many people might wonder why\r\n% someone would make such a simple mistake. Did the person miscount the\r\n% number of zeroes?\r\n%\r\n% I think I have an idea. This was written in Japan. In Japan, and in many\r\n% other Asian countries,\r\n% <http:\/\/en.wikipedia.org\/wiki\/Japanese_numerals#Large_numbers large\r\n% numbers> are grouped in myriads (every 10000). $10^4$ is called _man_\r\n% (\u8373), $10^8$ is called _oku_ (\u8706), $10^{12}$ is called _cho_ (\u8708). However\r\n% in Western counting, large numbers are grouped in 1000s - thousand,\r\n% million, billion, trillion, etc. So, it's likely that the person writing\r\n% the check wrote \"19050\", read it as \"1 _man_ 9050\", and incorrectly\r\n% translated to \"1 thousand 9 hundred 50\". Maybe...\r\n%\r\n% Anyway, all of this could have been avoided if this person had access to\r\n% Stephen's |num2words|! Just let his function spell out the number in\r\n% words.\r\n\r\nnum2words(19050)\r\n\r\n%%\r\n% This is the simplest use case, but |num2words| comes with a wealth of\r\n% options to customize how the results are returned.\r\n\r\nnum2words(19050,'type','cheque')\r\n\r\n%%\r\n% Stephen includes a detailed help in the function, so you can learn about\r\n% all the options just by typing\r\n%\r\n%   help num2words\r\n%\r\n% What gave me a little chuckle was that when I looked inside his function,\r\n% I could see that he made sure that his function can count up to\r\n% _Uncentillion_ which is $10^{306}$. So if you need to spell out a number\r\n% larger than $10^{309}$, you might be out of luck. :)\r\n% \r\n% *Comments*\r\n%\r\n% Give this a try, and let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=5794#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/47221-number-to-words#comments\r\n% comment> for Stephen.\r\n##### SOURCE END ##### a594f68b23c34d28866f46c3d2b56a95\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_numbertowords\/potw_numbertowords_eq14079313239914964384.png\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n   Jiro's pick this week is num2words by Stephen Cobeldick.\r\n   \r\n   Just recently, I witnessed a typo on a check payment. The amount was for \"$19050\" (unfortunately, it wasn't for me) but the... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2015\/01\/09\/spelling-out-numbers\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5794"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=5794"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5794\/revisions"}],"predecessor-version":[{"id":5798,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5794\/revisions\/5798"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=5794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=5794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=5794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}