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

doubleroundUp(double val)
round Up
int exponent = (int) Math.floor(Math.log10(val));
val *= Math.pow(10, -exponent);
if (val > 5.0)
    val = 10.0;
else if (val > 2.0)
    val = 5.0;
else if (val > 1.0)
    val = 2.0;
...
doubleroundUp(double val)
round Up
int exponent = (int) Math.floor(Math.log10(val));
val *= Math.pow(10, -exponent);
if (val > 5.0)
    val = 10.0;
else if (val > 2.0)
    val = 5.0;
else if (val > 1.0)
    val = 2.0;
...
doubleroundUp(final double val)
Given a number, round up to the nearest power of ten times 1, 2, or 5.
int exponent = (int) Math.floor(Math.log10(val));
double rval = val * Math.pow(10, -exponent);
if (rval > 5.0) {
    rval = 10.0;
} else if (rval > 2.0) {
    rval = 5.0;
} else if (rval > 1.0) {
    rval = 2.0;
...
introundUp(final int number, final int base)
Rounds an integer division to the nearest integer.
return (number + base - 1) / base;
longRoundUp(final T number)
Returns a long number by round up with specify number.
Returns 0 if number == null.
e.g: average is 3.5, then return 4.
if (number == null) {
    return 0;
double value = number.doubleValue();
if (value % 1 == 0) {
    return (long) value;
} else {
    return (long) (value + 1);
...
introundUp(int capacity)
round Up
int tz = 32 - Integer.numberOfLeadingZeros(capacity - 1);
return 1 << tz;
introundUp(int dividend, int divisor)
round Up
int remainder = dividend % divisor;
dividend -= remainder;
if (remainder * 2 > divisor) {
    dividend += divisor;
return dividend;
introundUp(int groupSize, int globalSize)
round Up
int r = globalSize % groupSize;
if (r == 0) {
    return globalSize;
} else {
    return globalSize + groupSize - r;
introundUp(int groupSize, int globalSize)
rounded up to the nearest multiple of the groupSize
int r = globalSize % groupSize;
if (r == 0) {
    return globalSize;
} else {
    return globalSize + groupSize - r;
introundUp(int i, int snap)
round Up
return roundDown(i + snap - 1, snap);