Thanks, David, that was too quick. I already tried it, but the script won’t work if a number contain commas. So, I have to remove it first. Second, the sub-dropdown is disabled.
However, I tried to add some code to the script to remove the existing commas:
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = ',';
app.documents[0].selection[0].changeGrep();
…and then I enabled the sub-dropdown list by commenting the line so that I can select:
//enabled = false;
Now I can say the script is working fine. However, I think that the dialog box should not be there and I can figure out that the actual working code lies in this area. I tried to tweak it but didn’t get any success.
var D, E = "", G, X;
D = decimalDropdown.selection.index ? "," : ".";
G = delimiterDropdown.selection.index ? "\u2009" : ",";
D == "." && E = "";
X = "d+"+E+D+"{0,1}d+";
app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = X;
var myFinds = s.findGrep(), f, n, t, d;
while (f = myFinds.pop()){
n = f.contents.toString().split('.');
// Add commas to thousands
if (!ignore4.value || (n[0] && n[0].length > 4)){
t = n[0].split('').reverse().join('').match(/.{1,3}/g).join(G).split('').reverse().join('');
}
// Add commas to decimals if there are any.
if (!ignore4.value || (n[1] && n[1].length > 4)){
n[1] && (d = n[1].match(/.{1,3}/g).join(G), t += D + d);
}
t && f.contents = t;
}
}
Apart from this, the code also converts any numbers be it phone numbers or a year. It will be good if the script can sense numbers that starts with a Dollar($) or Pound(£) or Euro(€) symbol.