Java Utililty Methods floor

List of utility methods to do floor

Description

The list of methods to do floor are organized into topic(s).

Method

doublefloor(double a)
Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.
return Math.floor(a);
doublefloor(double a, double precision)
Returns a rounded number smaller than a with a defined precision.
if (precision == 0.0) {
    return 0.0;
return Math.floor(a / precision) * precision;
doublefloor(double a, int cutOfDigits)
Modification of Math#floor(double) taking an additional argument representing the requested accuracy in the following way:
double fac = Math.pow(10, digits);
return fac * Math.floor(a / fac);
double fac = Math.pow(10, cutOfDigits);
return fac * Math.floor(a / fac);
doublefloor(double a, int n)
floor
double p = Math.pow(10.0, n);
return Math.floor((a * p) + 0.5) / p;
intfloor(double d)
floor
return (int) (d + FLOOR) - INT;
intfloor(double d)
floor
return (int) Math.floor(d);
intfloor(double d)
Unchecked implementation to round a number down.
int i = (int) d;
return d < i ? i - 1 : i;
doublefloor(double d, int exp)
This method returns the largest double value that is smaller than d = x * 10exp where x is rounded down to the closest integer.
double x = 1.0 * Math.pow(10.0, (double) exp);
return Math.floor(d / x) * x;
doublefloor(double d, int p)
floor
long tmp = (long) Math.pow(10, p);
double num = Math.floor(d * tmp);
num /= tmp;
return num;
intfloor(double num)
floor
final int numInt = (int) num;
return numInt == num ? numInt : numInt - (int) (Double.doubleToRawLongBits(num) >>> 63);