Java Utililty Methods Integer Divide

List of utility methods to do Integer Divide

Description

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

Method

intdiv(int a, int b)
div
return (a + b / 2) / b;
intdiv(int a, int b)
div
if (b == 0)
    return 0x7fffffff;
if (a == 0x80000000 && b == -1) {
    return 0x7fffffff;
return a / b;
intdiv(int a, int b)
div
if (b != 0) {
    return a / b;
} else
    throw new ArithmeticException("Divisor is Zero");
floatdiv(int dividend, int divisor)
div
return ((float) dividend) / ((float) divisor);
intdiv(int val, int coe)
div
return val / coe + (val % coe > 0 ? 1 : 0);
Stringdivce(long size, long divider, int i)
divce
if (i > 0) {
    if (size % divider != 0) {
        double re = ((double) size) / divider;
        return String.format("%." + i + "f", re);
    } else {
        return String.valueOf(size / divider);
} else {
...
intdivCeil(int a, int b)
div Ceil
if (b < 0)
    return divCeil(-a, -b);
else if (b > 0) {
    if (a >= 0)
        return ((a + b - 1) / b);
    else
        return a / b;
} else
...
intdivCeil(int a, int b)
div Ceil
return a / b + ((a % b == 0) ? 0 : 1);
intdivCeil(int a, int b)
div Ceil
return (a + b - 1) / b;
intdivCeil(int nNumerator, int nDenominator)
Returns ceil (nNumerator / nDenominator).
return (nNumerator + nDenominator - 1) / nDenominator;