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)
round
return Math.round(d * 100D) / 100D;
doubleround(double d)
Rounds the number to 4 significant digits
if (d == 0.0)
    return d;
int digits = (int) (Math.log(d) / Math.log(10));
return round(d, 3 - digits);
intround(double d)
Round a double
int i = (int) d;
double result = d - i;
if (result < 0.5D)
    return i;
return i + 1;
intround(double d)
round
return floor(d + 0.5d);
intround(double d)
round
return (int) Math.round(d);
longround(double d)
round
if (d < 0) {
    return (long) (d - 0.5);
} else {
    return (long) (d + 0.5);
intround(double d)
Unchecked implementation to round a number.
return (int) (d + 0.5D);
intround(double d)
Round.
return (int) Math.round(d);
doubleround(double d, int decimalPlacesRequired)
Reduces the precision of a double to a specified number of decimal places.
double factor = Math.pow(10, decimalPlacesRequired);
return Math.round((d * factor)) / factor;
doubleround(double d, int decimals)
round
if (d != d) {
    return Double.NaN;
double n = Math.pow(10, decimals);
return Math.round(d * n) / n;