List of utility methods to do Number Round
int | roundToMultipleXLength(int inLength, int multipler) round To Multiple X Length if (multipler == 0) return inLength; return inLength % multipler == 0 ? inLength : inLength + multipler - inLength % multipler; |
double | roundToN(double d, int n) Rounds the d to n decimal places. double places = StrictMath.pow(10, n); double p = StrictMath.round(d * places) / places; return p; |
double | roundToNDecimalPlaces(final double in, final int n) Rounds the double to the given number of decimal places. if (n < 1) { throw new IllegalArgumentException("cannot round to " + n + " decimal places"); final double mult = Math.pow(10, n); return Math.round((in + Math.ulp(in)) * mult) / mult; |
double | roundToNDigits(double d, int n) round To N Digits if (d == 0) return d; int log = (int) Math.log10(d); int exp = n; exp -= log; int ival = (int) (Math.round(d * Math.pow(10, exp))); return ival / Math.pow(10, exp); |
double | roundToNearest(double d) round To Nearest return Math.floor(d + 0.5);
|
double | roundToNearest(double number) round To Nearest if ((int) (number + .5) >= (int) (number)) return (int) number + 1; return (int) number; |
int | roundToNearest(int num, int nearest) Rounds the number to the nearest. return (int) (nearest * Math.round((double) num / (double) nearest)); |
int | roundToNearestEven(int mantissa, int numOfBitsToRoundOff) Rounds the mantissa with bitsRoundOff assert (numOfBitsToRoundOff < 32); int a = 1 << (numOfBitsToRoundOff - 1) - 1; int b = (mantissa >> numOfBitsToRoundOff) & 1; return (mantissa + a + b) >> numOfBitsToRoundOff; |
int | roundToNearestInterval(int i, int j) round To Nearest Interval return Math.round(i / j) * j;
|
int | roundToNearestK(float v, int k) round To Nearest K return (int) (Math.round(v / k) * k); |