List of utility methods to do Double Number Round
double | round(double num) round double floor = Math.floor(num); if (num - floor >= 0.5) { return Math.ceil(num); } else { return floor; |
String | round(Double num) round return String.format("%.2f", num); |
double | round(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); |
double | round(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; |
double | round(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; |
double | round(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; |
double | round(double number) Rounds an argument number with precision of 2 decimal digits. return round(number, 2);
|
double | round(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;
|
double | round(double number, int decimal) round return Math.round(number * Math.pow(10, decimal)) / Math.pow(10, decimal);
|
double | round(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); |