3

我想做这个功能的相反我想将数字从阿拉伯语转换为英语

       <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>
4

1 回答 1

5

假设您要转换的数字已经在一个字符串中,那么类似下面的代码片段将起作用:

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;
}

最初从此处获取在 html 页面中从英文数字转换为阿拉伯数字

于 2013-05-16T05:52:35.633 回答