title: Converting arabic numbers into chinese financial numbers
body: <p>I am trying to create a function in functional programming, which recieves a normal Int value and translates it to financial chinese numbers and returns a String, for exaple: 301 = 三百零一. To begin, I have two maps, one with every digit from 0 to 9, and the other one with the exponentials, from 10, to 1000000.</p>
  <p><code>val digits: Map[Int, String] = Map(0 -&gt; &quot;〇&quot;, 1 -&gt; &quot;壹&quot;, 2 -&gt; &quot;貳&quot;, 3 -&gt; &quot;參&quot;, 4 -&gt; &quot;肆&quot;, 5 -&gt; &quot;伍&quot;, 6 -&gt; &quot;陸&quot;, 7 -&gt; &quot;柒&quot;, 8 -&gt; &quot;捌&quot;, 9 -&gt; &quot;玖&quot;);</code></p>
  <p><code>val exponent: Map[Int, String] = Map(1 -&gt; &quot;&quot;, 10 -&gt; &quot;拾&quot;, 100 -&gt; &quot;佰&quot;, 1000 -&gt; &quot;仟&quot;, 10000 -&gt; &quot;萬&quot;, 100000 -&gt; &quot;億&quot;, 1000000 -&gt; &quot;兆&quot;);</code></p>
  <p>For the ones who don´t know, here goes a little explanation about how chinese numbers work. If you already know, don´t bother in reading this paragraph. In the chinese numbers, when you want to write a large number, for example 5000, you write the 5 and the 1000 symbols (伍仟) to intimate that you are multiplying 5 * 1000. If you have 539, it´s 5<em>100 + 3</em>10 + 9. This would be 伍佰參拾玖. Lastly, if the number has 0´s between multiplications, it doesn´t matter how many they are, you write only one 0 between the other characters. For example: 501 = 5<em>100 + 1. This is 伍佰〇壹. One last example for calrification: 50103 = 5</em>10000 + 1*100 + 3. This is 伍萬〇壹佰〇參.</p>
  <p>So what I could do, is the following:</p>
  <pre><code>def format(unit: Int): String = {
  val l = unit.toString.map(_.asDigit).toList
  if(l.isEmpty) &quot;&quot;
  else if(l.tail.isEmpty) digits(l.head)
  else digits(l.head) + format(l.tail.mkString.toInt)
  }
  </code></pre>
  <p>This translates the characters one by one. For example:</p>
  <pre><code>format(135) &quot;壹參伍&quot;
  </code></pre>
  <p>And I don´t know how to continue.</p>