我编写了以下代码将数字更改为波斯语:
function farsi(x) {
x = x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
var a = '۰۱۲۳۴۵۶۷۸۹'; var b = '';
for (var i = 0; i < x.length; i++) {
var c = x.charCodeAt(i);
b += (c >= 48 || c <= 57 ? a.charAt(c - 48) : x.charAt(i));
}
return b;
}
我使用正则表达式来自How to print a number with commas as thousands separators in JavaScript的千位seprator,它正常工作。但是在这行代码中没有添加分隔符:
b += (c >= 48 || c <= 57 ? a.charAt(c - 48) : x.charAt(i));
以下是fiddle