-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
41 lines (39 loc) · 1.22 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function persianToEnglish(value) {
var newValue = "";
for (var i = 0; i < value.length; i++) {
var ch = value.charCodeAt(i);
if (ch >= 1776 && ch <= 1785) // For Persian digits.
{
var newChar = ch - 1728;
newValue = newValue + String.fromCharCode(newChar);
}
else if (ch >= 1632 && ch <= 1641) // For Arabic & Unix digits.
{
var newChar = ch - 1584;
newValue = newValue + String.fromCharCode(newChar);
}
else
newValue = newValue + String.fromCharCode(ch);
}
return newValue;
}
function EnglishToPersian(value) {
var newValue = "";
for (var i = 0; i < value.length; i++) {
var ch = value.charCodeAt(i);
if (ch >= 48 && ch <= 57) // For Persian digits.
{
var newChar = ch + 1728;
newValue = newValue + String.fromCharCode(newChar);
}
else if (ch >= 1632 && ch <= 1641) // For Arabic & Unix digits.
{
var newChar = ch + 144;
newValue = newValue + String.fromCharCode(newChar);
}
else
newValue = newValue + String.fromCharCode(ch);
}
return newValue;
}
EnglishToPersian("12");