Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>-module(int2txt). -export([convert/1]). convert(0) -&gt; "zero"; convert(N) -&gt; convert1(N). convert1(0) -&gt; ""; convert1(N) when N&gt;=1000 -&gt; join(convert_thou(thoubit(N), 0),convert1(N rem 1000)); convert1(N) when N&gt;=100 -&gt; join(convert1(N div 100),"hundred",convert1(N rem 100)); convert1(N) when N&gt;=20 -&gt; join(tens((N div 10)-1) ++"ty",convert1(N rem 10)); convert1(N) when N&gt;=13 -&gt; teens(N-12) ++ "teen"; convert1(N) -&gt; ones(N). convert_thou({0,0},_) -&gt; ""; convert_thou({0,N2},C) -&gt; convert_thou(thoubit(N2),C+1); convert_thou({N,N2},C) -&gt; join(convert_thou(thoubit(N2),C+1), convert1(N),thouword(C)). thoubit(N) -&gt; {(N div 1000) rem 1000,N div 1000}. ones(N) -&gt; element(N,{"one","two","three","four","five","six","seven", "eight","nine","ten","eleven","twelve"}). tens(N) -&gt; element(N,{"twen","thir","for","fif","six","seven","eigh","nine"}). teens(2) -&gt; "four"; teens(N) -&gt; tens(N+1). thouword(0) -&gt; "thousand"; thouword(C) -&gt; illions(C) ++ "illion". illions(N) -&gt; element(N,{"m","b","tr","quadr","quint","sex","sept", "oct","non","dec"}). join(X,Y,Z) -&gt; join(join(X,Y),Z). join("",X) -&gt; X; join(X,"") -&gt; X; join(X,Y) -&gt; X++" "++Y. </code></pre> <p>Tests:</p> <pre><code>1&gt; int2txt:convert(0). "zero" 2&gt; int2txt:convert(1024). "one thousand twenty four" 3&gt; int2txt:convert(1048576). "one million forty eight thousand five hundred seventy six" 4&gt; int2txt:convert(1073741824). "one billion seventy three million seven hundred forty one thousand eight hundred twenty four" 5&gt; int2txt:convert(1000001). "one million one" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload