Java Utililty Methods Number Round

List of utility methods to do Number Round

Description

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

Method

doubleroundUpNumberByUsingMultipleValue(double number, double multiple)
Round up number by using multiple value.
double result = multiple;
if (number % multiple == 0) {
    result = number;
} else if (number % multiple != 0) {
    if (number >= 0) {
        int division = (int) ((number / multiple) + 1);
        result = division * multiple;
    } else {
...
introundUpPOT(int value)
round Up POT
return 1 << (32 - Integer.numberOfLeadingZeros(value - 1));
introundUpPow2(int x)
Rounds an integer up to the next power of 2.
if (x <= 0) {
    return 1;
} else if (x > 0x40000000) {
    throw new IllegalArgumentException(
            "Rounding " + x + " to the next highest power of two would exceed the int range");
} else {
    x--;
    x |= x >> 1;
...
introundUpPower2(int i)
round Up Power
i--;
i |= i >> 1;
i |= i >> 2;
i |= i >> 4;
i |= i >> 8;
return (i | (i >> 16)) + 1;
introundUpPower2(int v)
round Up Power
switch (Integer.bitCount(v)) {
case 0:
    return (1);
case 1:
    return (v);
default:
    return (Integer.highestOneBit(v) << 1);
doubleroundUpTo(double in, double del)
round in up to the next even multiple of del
int n = (int) (in / del);
double ret = n * del;
if (ret == in)
    return (ret);
return (ret + del);
introundUpTo(int a, int quanta)
round Up To
return (a + (quanta - 1)) & -quanta;
longroundUpTo(long i, long multiple)
round Up To
return (i + multiple - 1L) & ~(multiple - 1L);
introundUpTo100(int n)
round Up To
int rem = n % 100;
if (rem == 0)
    return n;
return n + (100 - rem);
longroundUpTo8(final long number)
round Up To
return ((number + 7) / 8) * 8;