将数字从阿拉伯语转换为英语 [英] convert numbers from arabic to english

查看:205
本文介绍了将数字从阿拉伯语转换为英语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要执行此功能的反向
i想要将数字从阿拉伯语转换为英语

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


推荐答案

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

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

这篇关于将数字从阿拉伯语转换为英语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆