Login  Register

Re: String.format

Posted by Wayne Rasband-2 on Nov 18, 2020; 4:44pm
URL: http://imagej.273.s1.nabble.com/String-format-tp5024199p5024201.html

> On Nov 18, 2020, at 10:53 AM, Peter Haub <[hidden email]> wrote:
>
> Hi,
> I would like to execute the macro function:
>
> s = String.format("%04d", 13);
> print(s);
>
> but I get the error message

Change the ā€˜d’ (integer) to ā€˜f’ (float) and it will work. All numbers in the ImageJ macro language are stored as doubles.

-wayne


> "java.util.IllegalFormatConversionException: d != java.lang.Double in
> line 1:"
> "s = String . format ( "%04d" , 13 <)> ;"
>
> If the number is float and not integer It's working:
>
> s = String.format("%04f", 13.0);
> print(s);
>
> Could this be a bug?
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html