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(double d, int i)
round
long powerTen = 1;
for (int x = 0; x < i; x++) {
    powerTen *= 10;
return ((double) Math.round(d * powerTen)) / powerTen;
doubleround(double d, int numDecimal)
Round specified value to specified number of decimal.
final double pow = Math.pow(10, numDecimal);
return Math.round(d * pow) / pow;
doubleround(double d, int p)
round
long tmp = (long) Math.pow(10, p);
double num = Math.round(d * tmp);
num /= tmp;
return num;
doubleround(double d, int precision)
round
int temp = (int) ((d * Math.pow(10, precision)));
return (((double) temp) / Math.pow(10, precision));
floatRound(double d, int Rpl)
rounds a number to RPL places
float p = (float) Math.pow(10, Rpl);
d = d * p;
float tmp = Math.round(d);
return (float) tmp / p;
doubleround(double dValue)
round
return Math.rint(dValue * m_dFractionMultiplier) / m_dFractionMultiplier;
doubleround(double input)
A quick way to round numbers.
input = input * 1000.0;
int tempInt = (int) input;
double output = ((double) tempInt) / 1000;
return output;
doubleround(double input, double step)
Method rounds input number by a specific step
return ((Math.round(input / step)) * step);
intround(double n)
Round to the nearest integer.
This is different from Math.round() for negative number.
return (int) ((n > 0 ? 0.5 : -0.5) + n);
doubleround(double n, double nd)
round
if (isFinite(n) && isFinite(nd)) {
    double sign_n = (n < 0) ? -1 : 1;
    double abs_n = Math.abs(n);
    double factor = Math.pow(10, nd);
    return sign_n * Math.round(abs_n * factor) / factor;
} else {
    return Double.NaN;