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 num)
round
double floor = Math.floor(num);
if (num - floor >= 0.5) {
    return Math.ceil(num);
} else {
    return floor;
Stringround(Double num)
round
return String.format("%.2f", num);
doubleround(double num, int bit)
round
int t = 10;
for (int i = 0; i < bit; i++)
    t *= 10;
double n = num * t;
if (5 <= (n % 10))
    n += 10;
return (double) ((int) n / 10) / (t / 10);
doubleround(double num, int decimal)
Round-off double to given number of decimal places.
double factor = Math.pow(10, decimal);
return Math.rint(num * factor) / factor;
doubleround(double num, int numDecs, boolean rawFactor)
Round a number to xyz decimal values ...
double ex = numDecs;
if (!rawFactor)
    ex = Math.pow(10, numDecs);
return Math.round(num * ex) / ex;
doubleround(double num, int precision)
Rounds num to the precision-th decimal place.
double modifier = Math.pow(10, precision);
double result = Math.round(num * modifier);
return result / modifier;
doubleround(double number)
Rounds an argument number with precision of 2 decimal digits.
return round(number, 2);
doubleround(double number, double multiplier)
Rounds the number of decimal places based on the given multiplier.
e.g.
Input: 17.5245743
multiplier: 1000
Output: 17.534
multiplier: 10
Output 17.5

return Math.round(number * multiplier) / multiplier;
doubleround(double number, int decimal)
round
return Math.round(number * Math.pow(10, decimal)) / Math.pow(10, decimal);
doubleround(double number, int digit)
Rounds a number to keep specified digits.
long l = Math.round(number * Math.pow(10, digit));
return (double) l / Math.pow(10, digit);