Setting number of decimal places for calculation

Hello, I don’t quite understand how ImageJ decides how many decimal places will be used for calculation, exporting results, etc.

The following macro illustrates why I am am a bit confused:

run("Blobs (25K)");
setAutoThreshold("Default");
run("Set Measurements...", "area mean perimeter shape redirect=None decimal=2");
run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 display clear add");

function doCalculation(columnName) {
	numbers = newArray(nResults);
	for (j=0; j<nResults; j++) {
		numbers[j] = getResult(columnName, j);
	}
	// do calculation here:
	Array.getStatistics(numbers, min, max, mean, std);
	result = min + max * mean
	return result;
	}

result = doCalculation("Circ.");
print("Result: " + result);

print("Result: " + doCalculation("Circ."));

close("*");

Using ImageJ 1.52p, I get the following result:

Result: 1.2392
Result: 1.239242024509032

When going the way to first put the result, calculated by the function, into a variable, ImageJ uses 4 decimal places, while it’s 15 when I use the “output” of the function directly. In either case the setting to 2 decimal places set by “Set measurments…” is ignored.

I couldn’t find any information on how ImageJ handles decimal places, so I would be happy if someone could explain or link me to some guide or manual that I’ve overseen. Thanks already!

Numeric expressions are automatically converted to strings using four decimal places, or use the
d2s function to specify the decimal places. For example, print(2/3) outputs "0.6667" but
print(d2s(2/3,1)) outputs "0.7".`Preformatted text`

from
https://imagej.nih.gov/ij/developer/macro/functions.html

1 Like

Thank you!
https://imagej.nih.gov/ij/developer/macro/functions.html#print and https://imagej.nih.gov/ij/developer/macro/functions.html#d2s do explain what I didn’t know.