I would like to convert an integer into a string with leading zeros in ImageJ / Fiji macro editor using String.format()
function. With this code:
s = String.format("%04d", 13);
print(s);
I get the following error:
Unrecognized String function in line 2
s = String . <format> ("%04d" , 13);
Any ideas?
After the documentation https://imagej.nih.gov/ij/developer/macro/functions.html#S this should work:
String.format(format, number) - Returns a formatted string using the specified format and number.
Version: ImageJ 1.53c with Java 1.8.0_172 (64-bit)
The String.format
macro function requires ImageJ 1.53d or newer. The version of ImageJ 1.x shipped with Fiji is a few versions behind due to breaking changes in ImageJ 1.x that the ImageJ2 team still need to work around. In the meantime, you can use the Help > Update ImageJ... command to update the version of ImageJ 1.x bundled with Fiji. Be aware that this command will hard quit your running ImageJ instance after downloading the chosen version.