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 zahl, int stellen)
round
double d = Math.pow(10, stellen);
return Math.round(zahl * ((long) d)) / d;
double[]round(double[] arr)
round
double[] result = new double[arr.length];
for (int i = 0; i < arr.length; i++) {
    result[i] = Math.round(arr[i]);
return result;
double[]round(double[] array, int decimals)
Rounds a number to the nearest double given the number of required decimal places.
double[] out = new double[array.length];
for (int i = 0; i < array.length; i++) {
    out[i] = round(array[i], decimals);
return out;
double[][]round(double[][] data)
round
for (int i = 0; i < data.length; i++)
    for (int j = 0; j < data[i].length; j++)
        data[i][j] = Math.round(data[i][j]);
return data;
intround(final double num)
Round given number.
return floor(num + 0.5d);
doubleround(final double num, final int prec)
round
final double epsilon = 1.0e-4;
double r, rs, x, result;
double factor;
factor = Math.pow(10, prec);
x = num * factor;
r = Math.round(x);
if (r < x) {
    rs = Math.round(x + epsilon);
...
doubleround(final double numberToRound, final int decimalPlaces)
round
final int roundedNumber = (int) Math.round(numberToRound * Math.pow(10, decimalPlaces));
return roundedNumber / Math.pow(10, decimalPlaces);
doubleround(final double v)
Rounds the given number to a precision of two after digit numbers.
return ((long) (v * 100.)) / 100.;
doubleround(final double val, final int decimalPlaces)
Rounds a coordinate value (longitude or latitude) to a specific precision.
return Math.round(val * Math.pow(TEN, decimalPlaces)) / Math.pow(TEN, decimalPlaces);
doubleround(final double val, final int decimals)
Rounds the given double value to a certain number of decimal places.
if (decimals >= 0) {
    long fact = powerOfTen(decimals);
    return Math.round(val * fact) / ((double) fact);
} else {
    long fact = powerOfTen(-decimals);
    return Math.round(val / fact) * ((double) fact);