我想反过来这个功能 我想将数字从阿拉伯语转换为英语
<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>
答案 0 :(得分: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;
}
从这里开始Convert from English Digits to Arabic ones in html page