3

I want to do the reverse of this function. I want to convert numbers from Arabic to English.

<script type="text/javascript">
       function numentofa(n) {
        var digits = [],
            r;
        do {
            r = n % 10;
            n = (n - r) / 10;
            digits.unshift(String.fromCharCode(r + 1776));
        } while (n > 0);
        return digits.join('');
        }
       
        window.onload = aa();
        
        function aa() {
            var oooook = numentofa("121");
            $('.numbers').append(oooook);
            alert(oooook);
        }
    
       
</script>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • @zerkms i think this platform is for help to people with their coding problems so if you can help then you do if you can't then you not do this kind of comment – The Mechanic May 16 '13 at 05:23
  • @The Mechanic: you're absolutely right. We're here to help solving tasks, not to do other people's job for free. OP didn't provide anything, but a task for us to do. – zerkms May 16 '13 at 05:24
  • then you can ask for him if he'll provide then you'll help if not then you don't – The Mechanic May 16 '13 at 05:25
  • 1
    @The Mechanic: then I don't "what"? OP should have already gotten the point. – zerkms May 16 '13 at 05:27
  • @zerkms and i'll appreciate it thanks :-) – The Mechanic May 16 '13 at 05:35
  • @The Mechanic: now you see - OP didn't even bother to discuss it here but added bold around his requirements :-) – zerkms May 16 '13 at 05:51
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/30034/discussion-between-the-mechanic-and-zerkms) – The Mechanic May 16 '13 at 05:53

1 Answers1

5

Assuming that the number you wish to convert is already in a string, then something like the following snippet of code will work:

function convertDigitIn(enDigit){ // PERSIAN, ARABIC, URDO
    var newValue="";
    for (var i=0;i<enDigit.length;i++)
    {
        var ch=enDigit.charCodeAt(i);
        if (ch>=48 && ch<=57
        {
            // european digit range
            var newChar=ch+1584;
            newValue=newValue+String.fromCharCode(newChar);
        }
        else
            newValue=newValue+String.fromCharCode(ch);
    }
    return newValue;
}

orginally take from here Convert from English Digits to Arabic ones in html page

Community
  • 1
  • 1
The Mechanic
  • 2,301
  • 1
  • 26
  • 37
  • 1
    this function converts eng to Arabic but not arabic numbers to english my input is '۱۲۳۴۵' and output i want is 12345 – Mir Shakeel Hussain May 16 '13 at 06:07
  • Except This is just copy of link you mentioned as @MirShakeelHussain said this is convert from english to persian or arabic, I wonder why got 5 plus point! – QMaster Nov 25 '17 at 14:53