Last active
August 29, 2015 14:03
-
-
Save intuxicated/62d86b1c43f265bd36b6 to your computer and use it in GitHub Desktop.
convert english numbers to persian number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pnumber(text){ | |
var en_to_persian = {"1":"۱", "2":"۲","3":"۳","4":"۴","5":"۵","6":"۶","7":"۷","8":"۸","9":"۹","0":"۰"} | |
var ar_to_persian = {"١":"۱", "٢":"۲","٣":"۳","٤":"۴","٥":"۵","٦":"۶","٧":"۷","٨":"۸","٩":"۹","٠":"۰"} | |
for (var val in en_to_persian) | |
text = text.replace(new RegExp(val, "g"), en_to_persian[val]); | |
for (var val in ar_to_persian) | |
text = text.replace(new RegExp(val, "g"), ar_to_persian[val]); | |
return text | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why you do it in two for loop? i think you can do it in just one loop!
var ar_and_en_to_persian = {"1":"۱", "2":"۲","3":"۳","4":"۴","5":"۵","6":"۶","7":"۷","8":"۸","9":"۹","0":"۰","١":"۱", "٢":"۲","٣":"۳","٤":"۴","٥":"۵","٦":"۶","٧":"۷","٨":"۸","٩":"۹","٠":"۰"}