Java Utililty Methods Double Number Round

List of utility methods to do Double Number Round

Description

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

Method

Doubleround(final Double value)
round
if (value != null) {
    return Math.floor(value.doubleValue() + 0.5d);
return value;
Floatround(final Double value)
Round to 0.x
if (value != null) {
    return (float) (Math.round(value * TEN)) / TEN;
return null;
doubleround(final double value, final int numDecimals)
round
final double factor = Math.pow(10.0, numDecimals);
return Math.round(value * factor) / factor;
doubleround(final double x, final int digits)
rounds up a double up to the specified number of digits after period.
final double d = Math.pow(10, digits);
return Math.round(x * d) / d;
intround2(double d)
Useful for hashCode() and equals() fn's that compare stuff read from a text file.
return (int) (d * 100 + 0.5);
doubleround2(double num)
round
double result = num * 100;
result = Math.round(result);
result = result / 100;
return result;
doubleround2(final double arg)
Returns the input argument, rounded to two decimal places.
double d = arg * 100.0;
final long longArg = Math.round(d);
return longArg / 100.0;
intround2(int a, int preserveDigits)
Math#round(double) -like operation for integers preserving the given number of digits in contrary to MathUtil#round(int,int) where cut-of-digits are specified:
return round(a, getDigits(a) - preserveDigits)
return round(a, getDigits(a) - preserveDigits);
Doubleround2Places(Double input)
round Places
return Math.round(input * 100.0) / 100.0;
doubleround5(final double value)
round
return Math.round(value * 100000.) / 100000.;