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 value, int scalar, int standard)
round
return Double.parseDouble(round(String.valueOf(value), scalar, standard));
doubleround(double valueToRound, int numberOfDecimalPlaces)
round
if (Double.isNaN(valueToRound))
    return Double.NaN;
double multipicationFactor = Math.pow(10, numberOfDecimalPlaces);
double interestedInZeroDPs = valueToRound * multipicationFactor;
return Math.round(interestedInZeroDPs) / multipicationFactor;
doubleround(double valueToTruncate, int requiredDecimalPlaces)
round
assert requiredDecimalPlaces >= 0 : "Can't round to a negative number of decimal places!";
double scalingFactor = Math.pow(10d, requiredDecimalPlaces);
double scaledValueToTruncate = valueToTruncate * scalingFactor;
int roundedScaledValueToTruncate = (int) (scaledValueToTruncate + 0.5d); 
return ((double) roundedScaledValueToTruncate) / scalingFactor;
doubleround(double what, int howmuch)
round
return (double) ((int) (what * Math.pow(10, howmuch) + .5)) / Math.pow(10, howmuch);
doubleround(double x)
round
return Math.floor((x + 0.5));
intround(double x)
A fast implementation of Math#round(double) .
return (int) (x + BIG_ENOUGH_ROUND) - BIG_ENOUGH_INT;
intround(double x)
Data un valore decimale ritorna un intero che lo arrotondato
return (int) Math.round(x);
doubleround(double x)
round
return round(x, 1);
doubleround(double x, int numPlaces)
round
double scale = Math.pow(10, numPlaces);
return Math.round(x * scale) / scale;
doubleround(double x, int places)
round
long m = pow(10, places);
return Math.rint(x * m) / m;