List of utility methods to do Double Number Divide
double[] | roundDivide(double[] dividend, double[] divisor, int scale) Returns an array whose members are the quotient of the dividend array values and the divisor array values. if (dividend.length != divisor.length) { throw new IllegalArgumentException("The dividend array and the divisor array must be the same length"); double[] quotient = new double[dividend.length]; for (int i = 0; i < dividend.length; i++) { quotient[i] = (dividend[i]) / (divisor[i] == 0 ? 1 : divisor[i]); quotient[i] = new BigDecimal(quotient[i]).round(new MathContext(scale, RoundingMode.HALF_UP)) .doubleValue(); ... |
long | safeDivide(long dividend, long divisor) Divides the dividend by the divisor throwing an exception if overflow occurs or the divisor is zero. if (dividend == Long.MIN_VALUE && divisor == -1L) { throw new ArithmeticException("Multiplication overflows a long: " + dividend + " / " + divisor); return dividend / divisor; |
double | toPercent(long divisor, long dividend) to Percent if (divisor == 0 || dividend == 0) { return 0d; double cd = divisor * 1d; double pd = dividend * 1d; return (Math.round(cd / pd * 10000) * 1d) / 100; |