Every so often, the question is raised how to add delimiters (commas, or thin spaces, etc.) between groups of 3 digits in long numbers in InDesign.
It would seem like this is something a clever GREP search could do, but in fact it is not so easy as it seems. In fact, I’m not sure it’s possible with a single simple GREP.
However, it is certainly possible with a script.
To use the script below, select something GREPable (text, a text frame, etc.), and run. Choose from the dropdown list the style of formatting you want. The available options are based on The Chicago Manual of Style (15th edition, chapter 9.23).
You can also choose to ignore numbers that are only 4 digits long (this might be useful to avoid formatting 4-digit years as well).
Click here to download the script: FormatLongNumbers
Here’s a screenshot.
Have fun!
MANSOOR MANIYAR
August 2, 2021 2:54 pmHi, Everyone,
I Want to download script…. but it isnt work… plz share the link
i have to insert commas in Indian value example
1
12
123
1,234
12,345
1,23,456
12,34,567
1,23,45,678
12,34,56,789
1,23,45,67,890
1,23,45,678.09
12,34,56,789.00
1,23,45,67,890.04
can you please help me
Ariel
August 13, 2021 2:07 amHi Mansoor,
Does Bhatt’s code (in the post immediately above yours) not work for you?
Ariel
Bhatt Saab
October 17, 2019 2:01 pmHi,
Used the same script and added a bit of my own code to get the Indian number format
if (!ignore4.value || (s[0] && s[0].length > 4)){
n = f.contents.toString();
n = n.replace(/,/g, ”);
var afterPoint = ”;
if (n.indexOf(‘.’) > 0) {
afterPoint = n.substring(n.indexOf(‘.’), n.length);
}
n = Math.floor(n);
n = n.toString();
var lastThree = n.substring(n.length – 3);
var otherNumbers = n.substring(0, n.length – 3);
if (otherNumbers != ”) lastThree = ‘,’ + lastThree;
t = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, “,”) + lastThree + afterPoint;
t && f.contents = t;
}
The only condition is you can not select multiple text boxes with number but all numbers inside one text box can be edited with this addition.