List of utility methods to do Double Number Round
double | round(double value, int nbDigits) round double val = value; if (nbDigits > 0) { double p = Math.pow(10, nbDigits); val = Math.round(value * p) / p; return val; |
double | round(double value, int numberOfDecimalPlaces) round double multipicationFactor = Math.pow(10, numberOfDecimalPlaces); return Math.round(value * multipicationFactor) / multipicationFactor; |
double | round(double value, int numDecimals) Round a value to the specified number of decimal places using the "Round Half Up" strategy. double scale = (numDecimals < 8) ? SCALE[numDecimals] : Math.pow(10, numDecimals); if (Math.ulp(value) * scale > 1d) return value; return Math.floor(value * scale + 0.5) / scale; |
double | round(double value, int places) round if (places < 0) throw new IllegalArgumentException(); long factor = (long) Math.pow(10, places); return (double) Math.round(value * factor) / factor; |
double | round(double value, int places) Round the given double value to the specified number of places after the decimal point. if (places < 0) throw new IllegalArgumentException(); long factor = (long) Math.pow(10, places); value = value * factor; long tmp = Math.round(value); return (double) tmp / factor; |
double | round(double value, int power) Relaxes precision up to the given power of 2. double scaled = Math.scalb(value, -power); return Math.scalb(Math.rint(scaled), power); |
double | round(double value, int precision) round double pow = Math.pow(10d, precision); double mulVal = pow * value; double kept = Math.floor(mulVal + 0.5d); return kept / pow; |
double | round(double value, int precision) Given a double value, return a new double with precision as given. double newValue = Math.round(value * Math.pow(10, precision)) / Math.pow(10, precision); return newValue; |
double | round(double value, int precision) Round a double up or down by the given number of decimal places double factor = Math.pow(10, precision); double result = Math.round(value * factor) / factor; return result; |
double | round(double value, int roundingFactor) round double doubleRounded = Math.round(value * roundingFactor); return doubleRounded / roundingFactor; |