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

doubleroundToDecimalPlaces(final double val, final int places)
Returns the given value rounded to the given precision.
final long power = (long) Math.pow(10, places);
return ((long) (val * power + 0.5)) / (double) power;
doubleroundToDecimals(double d, int c)
Rounds the given double to the given number of decimals
int temp = (int) ((d * Math.pow(10, c)));
return (((double) temp) / Math.pow(10, c));
doubleroundToDecimals(double d, int c)
round To Decimals
double denom = Math.pow(10, c);
return Math.round(d * denom) / denom;
doubleroundToDecimals(double d, int c)
Returns a value with the desired number of decimal places.
if (c < 0)
    return d;
double p = Math.pow(10, c);
d = d * p;
double tmp = Math.round(d);
return tmp / p;
doubleroundToDecimals(double d, int numberOfDecimalPlaces)
round To Decimals
int temp = (int) ((d * Math.pow(10, numberOfDecimalPlaces)));
return (temp / Math.pow(10, numberOfDecimalPlaces));
doubleroundToDecimals(double d, int percision)
Round a double to the given number decimal places
double p = (double) Math.pow(10, percision);
return (double) Math.round(d * p) / p;
doubleroundToDecimals(double doubleValue)
round To Decimals
return (roundToDecimals(doubleValue, 6));
doubleroundToDecimals(double input, int places)
round To Decimals
double log10 = Math.log10(input); 
double intLog10 = Math.floor(log10);
double scale = Math.pow(10, intLog10 - places + 1);
double factored = Math.round(input / scale) * scale;
return factored;
doubleroundToDefaultPrecision(final double value)
round To Default Precision
return (long) (P_ROUNDING_FACTOR * value + 0.5) / P_ROUNDING_FACTOR;
introundToDimensions(int value, int f)
Round.
return Math.round(value / f) * f;