/** * Returns the order of magnitude for the value <code>x</code>. * * @param x the input * * @return the order of magnitude: <code>Math.floor(log10(x))</code> */ public static double getOrderOfMagnitude(double x) { return Math.floor(log10(x)); }
/** * Computes a rounding factor suitable for the given value range and number of significant digits after the decimal * point. * * @param min the minimum value of the range * @param max the maximum value of the range * @param numDigits the number of significant digits after the decimal point, must be <code>>=0</code> * * @return the rounded value, always a power to the base 10 * * @see #round(double, double) */ public static double computeRoundFactor(final double min, final double max, int numDigits) { double exponent = log10(Math.abs(max - min)); int numLeadingZeroDigits = -(int) Math.round(exponent); if (numLeadingZeroDigits > 0) { numDigits += numLeadingZeroDigits; } return Math.pow(10.0, numDigits); }