List of utility methods to do Number Divide
T | div(Class div if (clazz == Double.class) return (T) Double.valueOf(a.doubleValue() / b.doubleValue()); if (clazz == Float.class) return (T) Float.valueOf(a.floatValue() / b.floatValue()); if (clazz == Integer.class) return (T) Integer.valueOf(a.intValue() / b.intValue()); if (clazz == BigDecimal.class) return (T) ((BigDecimal) a).divide((BigDecimal) b); ... |
Double | div(double a, double b, int len) div BigDecimal bdA = new BigDecimal(a); BigDecimal bdB = new BigDecimal(b); return bdA.divide(bdB, len, BigDecimal.ROUND_HALF_UP).doubleValue(); |
double | div(double operand1, double operand2) div return div(operand1, operand2, 10);
|
double | div(double v1, double v2) div return div(v1, v2, DEF_DIV_SCALE);
|
Double | div(Double v1, Double v2) div return div(v1, v2, DEFAULT_DIV_SCALE);
|
double | div(Double v1, Double v2) div if (v1 == null) { v1 = 0d; if (v2 == null) { v2 = 0d; double s1 = v1, s2 = v2; return div(s1, s2, 4); ... |
double | div(double v1, double v2) div BigDecimal b1 = new BigDecimal(Double.toString(v1)); BigDecimal b2 = new BigDecimal(Double.toString(v2)); return b1.divide(b2, 0, BigDecimal.ROUND_DOWN).doubleValue(); |
double | div(double v1, double v2, int scale) div if (scale < 0) { throw new IllegalArgumentException("The scale must be a positive integer or zero"); BigDecimal b1 = new BigDecimal(Double.toString(v1)); BigDecimal b2 = new BigDecimal(Double.toString(v2)); return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue(); |
long | div(long v1, long v2) div BigDecimal b1 = new BigDecimal(v1); BigDecimal b2 = new BigDecimal(v2); return b1.divide(b2, 0, BigDecimal.ROUND_HALF_UP).longValue(); |
Object | div(Object a, Object b) div if (a == null || b == null) { return null; BigDecimal decimalA = decimal(a); BigDecimal decimalB = decimal(b); try { return decimalA.divide(decimalB); } catch (ArithmeticException ex) { ... |