I written the following code to change the numbers to Persian:
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;
}
I have used the regex for thousand seprator from How to print a number with commas as thousands separators in JavaScript which works correctly. But the separator character is not being added in this line of code:
b += (c >= 48 || c <= 57 ? a.charAt(c - 48) : x.charAt(i));
Here is the fiddle