In indesign is it possible to automatically round numbers to x decimal places within a table?
2 Answers
Probably your best bet for this is to create the table in Excel, where you have good control over decimal places, and then link the table from InDesign to your Excel spreadsheet. There are a few things to watch out for in terms of holding your beautiful InDesign formatting, but these are very well explained through this complimentary Lynda tutorial at:
I used this, not using a table but should work the same.
https://creativepro.com/downloads/number_adjuster_1_2.zip
But it doesn't round up. So...
I edited the "return" line in the block below... Use case was for a restaurant menu. Increase price by 3%, then round up to the nearest 25 cents. Assuming with some fancy math you can do anything here.. I am no programmer, feel like I got lucky with experimenting. The "Math.ceil" rounds up. There are others that round down.
Got more info here https://stackoverflow.com/questions/45453312/math-round-only-up-quarter
Edit code in text editor, then loaded to indesign scripts.
//====================================================\
//Function to round numbers
function numRounder(myNumber, myRoundto)
{
myRoundMod = 1;
for(rounding = 0; rounding < myRoundto; rounding++)
{
myRoundMod = myRoundMod * 10;
}
return Math.ceil(4 * myNumber) / 4;
}