angular 将数字转换为波斯语

angular convert number to persian

我想在 angular 4:

中将英语数字转换为波斯语数字
persianNumbers = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"];
englishNumbers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
price="1000$";
price= this.fixnumber(price,this.persianNumbers,this.englishNumbers);


fixnumber(src,persian,english){
   for(var i=0; i<10; i++)
      {
        var str = /english[i]/gi;
        src = src.replace(str, persian[i]);
      }
    return src;
}

没用。

你应该试试 :

persianNumbers[i] = englishNumbers[i].toLocaleString('fa')

let enNumber = "50000$";
let faNumber = parseInt(enNumber.split('$')[0], 10).toLocaleString('fa-IR') + '$'; //۵۰٬۰۰۰$
console.log(faNumber);

使用map


let persianNumbersMap = new Map<string, string>();
map.set("0", "۰"); 
map.set("1", "۱");
map.set("2", "۲");
map.set("3", "۳");
map.set("4", "۳");
map.set("5", "۵");
map.set("6", "۶");
map.set("7", "۷");
map.set("8", "۸");
map.set("9", "۹");

使用:

map.get("1");

您可以使用这个功能:

function ConvertToPr(str) {
    return str.replace(/0/g,'٠').replace(/1/g,'١').replace(/2/g,'٢').replace(/3/g,'٣').replace(/4/g,'٤')
        .replace(/5/g,'٥').replace(/6/g,'٦').replace(/7/g,'٧').replace(/8/g,'٨').replace(/9/g,'٩')
        .replace(/۰/g,'٠').replace(/۱/g,'١').replace(/۲/g,'٢').replace(/۳/g,'٣').replace(/۴/g,'٤')
        .replace(/۵/g,'٥').replace(/۶/g,'٦').replace(/۷/g,'٧').replace(/۸/g,'٨').replace(/۹/g,'٩');
}

console.log(ConvertToPr("1000$")) //print ١٠٠٠$