Login  Register

Re: DecimalFormat method in macro

Posted by Wayne Rasband-2 on Aug 16, 2020; 11:17pm
URL: http://imagej.273.s1.nabble.com/DecimalFormat-method-in-macro-tp5023854p5023857.html

> On Aug 16, 2020, at 2:31 PM, CARL Philippe (LBP) <[hidden email]> wrote:
>
> Dear all,
> Is there an easy way apply something similar to the Java DecimalFormat("#0.000") feature within a macro ?
> I thank you very much in advance for your lighting on this.
> My best regards,
> Philippe

The ImageJ 1.53d61 daily build adds a String.format() macro function, which is the same as the String.format() method in Java.

Here is an example:

  arr = newArray(23.59004,35.7,3.0,9, 0);
  for (i=0; i<arr.length; i++)
     print(String.format(“%.3f", arr[i]));

And here is the output:

   23.590
   35.700
   3.000
   9.000
   0.000

-wayne

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