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

doubleroundTo2Decimals(double value)
round To Decimals
return (double) Math.round(value * 100) / 100;
doubleroundTo2Digits(double amount)
round To Digits
long number2 = Math.round(amount * 100);
return (double) (number2 / 100);
doubleroundTo2SigPlaces(double value)
Round double to 2- significant places
return Math.round(value * 100.0) / 100.0f;
doubleroundTo3Places(double n)
round To Places
return Math.round(n * 1000d) * 0.001;
DoubleroundTo6decimals(Double x)
round Todecimals
return x == null ? null : Math.round(x * Math.pow(10, 6)) / Math.pow(10, 6);
floatroundToAccuracy(float n, float i)
round To Accuracy
int cutoffN = (int) (n / i);
return cutoffN * i;
introundToBase(int a, int base)
Returns the nearest number to a multiple of a given number.
return a - a % base;
introundToBytes(int bitWidth)
Returns the number of bytes necessary to contain the given bit-width.
return (int) Math.ceil((double) bitWidth / 8);
longroundToDay(long time)
Rounds the time to an exact day.
return time / (24 * 60 * 60) * (24 * 60 * 60);
doubleroundToDecentPrecision(double value)
round To Decent Precision
double z = Math.round(roundValue * value);
return z / roundValue;