List of utility methods to do Double Number Round
String | getRatioString(double n, double d) get Ratio String if (d < 0.0001) { return "----"; DecimalFormat format = new DecimalFormat("#0.0%"); return format.format(n / d); |
double | round(double a) Returns a double rounded to the nearest integer. return Math.floor(a + 0.5);
|
int | Round(double a) Floor if Value < 0.5, Ceil if Value >= 0.5 int tmp = ((int) (a * 100)) % 100; if (tmp < 50) { return Floor(a); } else { return Ceil(a); |
int | round(double a) round return (int) (((a + 0.5) * 10.0) / 10.0); |
double | round(double a, double precision) Mathematically rounds a number with a defined precision. if (precision == 0.0) { return 0.0; return Math.round(a / precision) * precision; |
double | round(double a, int cutOfDigits) Modification of Math#round(double) taking an additional argument representing the requested accuracy in the following way: double fac = Math.pow(10, digits);
double fac = Math.pow(10, cutOfDigits); return fac * Math.round(a / fac); |
double | round(double a, int decimal) round try { String str = String.valueOf(a); int idx = str.indexOf("."); if (idx == -1 || idx == str.length() - 1) return Double.parseDouble(str); return Double.parseDouble(str.substring(0, Math.min(str.length(), idx + decimal + 1))); } catch (Exception e) { System.out.println("There is some error MathUtil.round: " + e.getMessage()); ... |
int | round(double a, int rounding_style) Returns the mathematically rounded part of a double value.
throw new UnsupportedOperationException("not yet implemented"); |
double | round(double amount) round double tmp1 = amount; long factor = (long) Math.pow(10, 2); tmp1 = tmp1 * factor; long tmp = Math.round(Math.abs(tmp1)); amount = ((amount < 0 && tmp != 0) ? -1 : 1) * ((double) tmp / factor); String[] strArr = String.valueOf(amount).split("\\."); return amount; |
double | round(double amt, int digits) round return (Math.round(Math.pow(10, digits) * amt)) / Math.pow(10, digits);
|