MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / getDecimalPlaces

Method getDecimalPlaces

ij/src/main/java/ij/util/Tools.java:222–235  ·  view source on GitHub ↗

Returns the number of decimal places needed to display a number, or -2 if exponential notation should be used.

(double n)

Source from the content-addressed store, hash-verified

220 /** Returns the number of decimal places needed to display a
221 number, or -2 if exponential notation should be used. */
222 public static int getDecimalPlaces(double n) {
223 if ((int)n==n || Double.isNaN(n))
224 return 0;
225 String s = ""+n;
226 if (s.contains("E"))
227 return -2;
228 while (s.endsWith("0"))
229 s = s.substring(0,s.length()-1);
230 int index = s.indexOf(".");
231 if (index==-1) return 0;
232 int digits = s.length() - index - 1;
233 if (digits>4) digits=4;
234 return digits;
235 }
236
237 /** Returns the number of decimal places needed to display two numbers,
238 or -2 if exponential notation should be used. */

Callers 6

getInfoMethod · 0.95
d2sMethod · 0.95
runMethod · 0.95
textValueChangedMethod · 0.95
createSubtitleMethod · 0.95
d2sMethod · 0.95

Calls 4

substringMethod · 0.80
lengthMethod · 0.65
containsMethod · 0.45
indexOfMethod · 0.45

Tested by

no test coverage detected