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

longroundUp(long number, long mod)
round Up
return ((number + mod - 1L) / mod) * mod;
longroundUp(long position, long sectionAlignment)
round Up
if (sectionAlignment < 0)
    throw new RuntimeException("Bad alignment: " + sectionAlignment);
if (sectionAlignment == 0)
    sectionAlignment = 1;
if (position % sectionAlignment != 0)
    return (position - (position % sectionAlignment)) + sectionAlignment;
return position;
longroundUp(long size, int blockSize)
round Up
return ((size + blockSize - 1) / blockSize) * blockSize;
longroundUp(long val, long delta)
round Up
boolean isNegative = val < 0;
val = Math.abs(val);
long old = val;
val = val / delta * delta;
if (val < old)
    val += delta;
return !isNegative ? val : -val;
longroundup_2n(long val, int blocksize)
Round up a value to the next multiple of a power of 2
int mask = blocksize - 1;
return (val + mask) & ~mask;
introundUpDivision(final int dividend, final int divider)
round Up Division
if (dividend == 0) {
    return 0;
return (dividend + divider - 1) / divider;
introundUpDown(int number, int by)
round Up Down
int result = number;
if (by > 0) {
    result = number + (by - number % by);
} else if (by < 0) {
    if (number % by == 0) {
        number--;
        result = number - number % by;
    } else {
...
longroundUpIfNecessary(long timeout, long convertedTimeout)
round Up If Necessary
if (timeout > 0 && convertedTimeout == 0) {
    return 1;
return convertedTimeout;
longroundUpLong(long value, long interval)
round Up Long
return ((value + interval - 1) / interval * interval);
longroundUpLong(long x, long blockSizePowerOf2)
Round the value up to the next block size.
return (x + blockSizePowerOf2 - 1) & (-blockSizePowerOf2);