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

floatroundTimeValue(final float defaultUnitValue, final boolean is24HourFormatting)
round Time Value
float unit = defaultUnitValue;
int multiplier = 1;
if (is24HourFormatting) {
    while (unit > 120) {
        multiplier *= 60;
        unit /= 60;
    if (multiplier >= 3600) {
...
DoubleroundTo(double aValue, int aDigits)
Rounds a double value to digit digits after the point.
double d = Math.pow(10, aDigits);
return new Double(Math.round(aValue * d) / d);
doubleroundTo(double d, int n)
returns the rounded result of the argument to the n digits after the decimal point.
d *= Math.pow(10, n);
d = Math.round(d);
d /= Math.pow(10, n);
return d;
doubleroundTo(double num, int dp)
round To
int dpM = (int) Math.pow(10, dp);
return Math.round(num * dpM) / dpM;
doubleroundTo(double val, double prec)
Rounds a double precision value to the given precision.
return floor(val / prec + 0.5) * prec;
doubleroundTo(final double VALUE, final double TARGET)
round To
return TARGET * (Math.round(VALUE / TARGET));
floatroundTo(float number, int base)
round To
return Math.round(number * 10 * base) / (10f * base);
floatroundTo(float number, int numPlaces)
(Based on round() in PHP)
if (numPlaces <= 1)
    return Math.round(number);
float exponent = (float) Math.pow(10, numPlaces);
return Math.round(number * exponent) / exponent;
floatroundTo(float val, int numPlaces)
Returns the rounded value of val to specified number of digits after the decimal point.
(Based on round() in PHP)
if (numPlaces <= 1)
    return Math.round(val);
float exponent = (float) Math.pow(10, numPlaces);
return (Math.round(val * exponent) / exponent);
doubleroundTo100th(double w)
round Toth
return Math.floor(w * 100 + 0.5) / 100;