How to convert unicode numbers to ints?
<blockquote>
  <p>Arabic and Chinese have their own glyphs for digits.  <code>int</code> works correctly with all the different ways to write numbers.</p>
</blockquote>

<p>I was not able to reproduce the behaviour (python 3.5.0)</p>

<pre><code>&gt;&gt;&gt; from unicodedata import name
&gt;&gt;&gt; name('í í¹¤')
'RUMI DIGIT FIVE'
&gt;&gt;&gt; int('í í¹¤')
ValueError: invalid literal for int() with base 10: 'í í¹¤'
&gt;&gt;&gt; int('äº')  # chinese/japanese number five
ValueError: invalid literal for int() with base 10: 'äº'
</code></pre>

<p>Am I doing something wrong?  Or is the claim simply incorrect (<a href="http://www.jjinux.com/2012/03/pycon-advanced-python-tutorials.html" rel="nofollow">source</a>).  </p>

<p>Here's a way to convert to numerical values (casting to <code>int</code> does not work in all cases, unless there's a secret setting somewhere)</p>

<pre><code>from unicodedata import numeric
print(numeric('äº'))
</code></pre>

<p>result: 5.0</p>

<p>Someone noted (and was right) that some arabic or other chars worked fine with <code>int</code>, so a routine with a fallback mechanism could be done:</p>

<pre><code>from unicodedata import numeric

def to_integer(s):
    try:
        r = int(s)
    except ValueError:
        r = int(numeric(s))
    return r
</code></pre>

<p>EDIT: as zvone noted, there are fraction characters that return floating point numbers: ex: <code>numeric('\u00be') is 0.75</code> (3/4 char). So rounding to int is not always safe.</p>

<p>EDIT2: the <code>numeric</code> function only accepts one character. So the "conversion to numeric" that could handle most cases without risks of rounding would be</p>

<pre><code>from unicodedata import numeric

def to_float(s):
    try:
        r = float(s)
    except ValueError:
        r = numeric(s)
    return r

print(to_float('ÛµÛµ'))
print(to_float('äº'))
print(to_float('Â¾'))
</code></pre>

<p>result:</p>

<pre><code>55.0
5.0
0.75
</code></pre>

<p>(I don't want to steal user2357112 excellent explanation, but still wanted to provide a solution that tries to cover all cases)</p>

python python-3.x unicode