Numbers localization in Web applications

前端 未结 8 702
渐次进展
渐次进展 2020-12-23 14:30

How can I set the variant of Arabic numeral without changing character codes ?

Eastern Arabic      ۰   ۱   ۲   ۳   ٦   ٥   ٤   ۷   ۸   ۹
Persian variant              


        
8条回答
  •  一生所求
    2020-12-23 15:27

    You can convert numbers in this way:

    const persianDigits = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
    const number = 44653420;
    
    convertedNumber = String(number).replace(/\d/g, function(digit) {
        return persianDigits[digit]
    })
    console.log(convertedNumber) // ۴۴۶۵۳۴۲۰
    

提交回复
热议问题