List of utility methods to do Double Number Divide
double | divide(double x, double y, int scale, RoundingMode roundingMode) divide BigDecimal xBigDecimal = new BigDecimal(String.valueOf(x)); BigDecimal yBigDecimal = new BigDecimal(String.valueOf(y)); BigDecimal resultBigDecimal = xBigDecimal.divide(yBigDecimal, scale, roundingMode); return resultBigDecimal.doubleValue(); |
double | divide(final double n1, final double n2) Divide. final BigDecimal b1 = new BigDecimal(n1); final BigDecimal b2 = new BigDecimal(n2 + ""); BigDecimal b3 = b1.divide(b2, 3, BigDecimal.ROUND_HALF_UP); b3 = b3.setScale(3, BigDecimal.ROUND_HALF_UP); final double result = b3.doubleValue(); return result; |
float | divide(float a, float b) Convert two float parameters into bigdecimal, divide together and return float value. BigDecimal a_bd = new BigDecimal(Float.toString(a)); BigDecimal b_bd = new BigDecimal(Float.toString(b)); return a_bd.divide(b_bd, 2).floatValue(); |
float | divide(float left, float right) Divides the given left float value by the given right float value. BigDecimal iLeft = new BigDecimal(left + ""); BigDecimal iRight = new BigDecimal(right + ""); try { return iLeft.divide(iRight).floatValue(); } catch (Exception e) { return iLeft.divide(iRight, BigDecimal.ROUND_HALF_DOWN).floatValue(); |
Double | divide(Number numerator, Number denominator) divide Double rtn = null; if (numerator != null && denominator != null) { double dNumerator = numerator.doubleValue(); double dDenominator = denominator.doubleValue(); if (dDenominator != 0) { BigDecimal bdNumerator = new BigDecimal(dNumerator); BigDecimal bdDenominator = new BigDecimal(dDenominator); rtn = bdNumerator.divide(bdDenominator, scale, RoundingMode.HALF_UP).doubleValue(); ... |
BigDecimal | divide(Object dividend, Object divisor) divide return new BigDecimal(dividend.toString()).divide(new BigDecimal(divisor.toString()), SCALE, ROUNDING_MODE); |
Double | divide(Object num1, Object num2) divide return divide(num1, num2, DEF_SCALE);
|
String | divide(String num1, String num2) divide BigDecimal n1 = new BigDecimal(num1); BigDecimal n2 = new BigDecimal(num2); return n1.divide(n2, 8, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString(); |
BigDecimal | divide(String num1, String num2, int scale) divide num1 = checkNum(num1); if ("".equals(num2)) { num2 = "1"; BigDecimal bd1 = new BigDecimal(num1); BigDecimal bd2 = new BigDecimal(num2); return bd1.divide(bd2, scale, BigDecimal.ROUND_HALF_UP); |
String | divide(String num1, String num2, int scale) divide BigDecimal dec1 = new BigDecimal(num1); BigDecimal dec2 = new BigDecimal(num2); return dec1.divide(dec2, scale, BigDecimal.ROUND_HALF_UP).toString(); |