Re: IJ.d2s "quirk"
Posted by Wayne Rasband on Sep 10, 2009; 3:36pm
URL: http://imagej.273.s1.nabble.com/IJ-d2s-quirk-tp3691174p3691177.html
> Hi again,
> I already note for some time, that IJ.ds2 has a "quirk"
> for very small values, for example
> double small_value = 9.915e-6;
> IJ.write(IJ.d2s (small_value, 2));
> will not output
> "0.00"
> but
> "9.915E-6"
> instead!
> Is this intended behaviour?
IJ.d2s() automatically switches to scientific notation for very small
values to prevent them from being misleadingly displayed in the Results
table as zero. You can avoid the use of scientific notation by
increasing the number of decimal places. Here is what you get
0 9.915E-6
1 9.915E-6
2 9.915E-6
3 9.915E-6
4 9.915E-6
5 9.915E-6
6 0.000010
7 0.0000099
8 0.00000992
9 0.000009915
when you run this macro
n = 9.915e-6;
for (d=0; d<=9; d++)
print(d2s(n,d));
-wayne
> Sometimes it might be useful to tell if a result is not exactly zero,
but
> *LARGER* numbers will nevertheless be rounded down to zero as for ex.
1e-3!