Here you can find the source of floory(double a, double precision)
double
value that is not greater than the argument and is equal for at least a precision value.
Math.floor(a/precision)*precision
.
public static double floory(double a, double precision)
//package com.java2s; public class Main { /**//from ww w. j av a 2 s. c o m * The default tolerance for two numbers to be treated equal. * (experimental) * @see #setDefaultTolerance(double) * @invariants DefaultTolerance ≥ 0 */ private static double DefaultTolerance = .00000000001; /** * Returns the largest (closest to positive infinity) * <code>double</code> value that is not greater than the argument and * is equal for at least a precision value. * <code>MathUtilities.floory(a, .01)</code> will result in <code>a</code> rounded down * to a number formated as <code>.##</code>, * while <code>MathUtilities.floory(a, 100)</code> will result in <code>a</code> rounded down * to a number formated as <code><i>several #s preceding</i>######<b>00</b>.</code>. * @return ⌊a/precision⌋*precision = <code>Math.floor(a/precision)*precision</code>. * @see #ceily(double, double) */ public static double floory(double a, double precision) { return Math.floor(a / precision) * precision; } public static double floory(double a) { return floory(a, precisionFor(a)); } /** * Get the precision for a given a specified tolerance relative to the magnitude of a. * <p> * Roughly gives the precision for tolerance percent of a, but adjusted to decimal digits. * </p> * @return tolerance * 10<sup>⌈㏒<sub>10</sub> a⌉</sup>. */ public static double precisionFor(double a, double tolerance) { return tolerance * Math.pow(10, Math.ceil(Math.log(a) / Math.log(10))); } /** * Get the precision for a default tolerance relative to the magnitude of a. */ public static double precisionFor(double a) { return precisionFor(a, DefaultTolerance); } }