Java Utililty Methods BigDecimal Divide

List of utility methods to do BigDecimal Divide

Description

The list of methods to do BigDecimal Divide are organized into topic(s).

Method

BigDecimaldivide(final BigDecimal amount, final BigDecimal divideBy, final int scale)
divide
return amount.setScale(scale, RoundingMode.HALF_EVEN).divide(divideBy, RoundingMode.HALF_EVEN);
longdivide(long res, BigDecimal value)
divide
if (value.equals(BigDecimal.ONE)) {
    return res;
} else if (value.compareTo(BigDecimal.ONE) < 0 && value.signum() == 1) {
    BigDecimal reciprocal = BigDecimal.ONE.divide(value, RoundingMode.UNNECESSARY);
    return reciprocal.multiply(BigDecimal.valueOf(res)).longValue();
} else {
    return res / value.longValue();
Vectordivide(Vector v, BigDecimal magnitude)
divide
Vector<BigDecimal> c = (Vector<BigDecimal>) v.clone();
for (int i = 0; i < c.size(); i++) {
    c.set(i, c.elementAt(i).divide(magnitude, MathContext.DECIMAL128));
return c;
voiddivideBigDecimalsInMap(Map baseMap, BigDecimal divisor)
divide Big Decimals In Map
if (baseMap == null || divisor == null || divisor.doubleValue() == 0.0)
    return;
for (Map.Entry<String, Object> entry : baseMap.entrySet()) {
    if (!(entry.getValue() instanceof BigDecimal))
        continue;
    BigDecimal baseVal = (BigDecimal) entry.getValue();
    entry.setValue(baseVal.divide(divisor, BigDecimal.ROUND_HALF_UP));
BigDecimaldivideBy(BigDecimal dividend, BigDecimal divisor)
Returns a BigDecimal whose value is (this / divisor) , and whose scale is as specified.
return dividend.divide(divisor, 4, HALF_EVEN);
BigDecimaldivideByTwo(BigDecimal number)
divide By Two
return number.divide(TWO, MathContext.DECIMAL32);
BigDecimaldivideMoeda(BigDecimal val1, BigDecimal val2)
divide Moeda
return val1.divide(val2, decMoeda, roundingMode);
BigDecimaldivideNonZeroValues(BigDecimal operand, BigDecimal divisor)
divide Non Zero Values
if (operand == null) {
    return BigDecimal.ONE;
if (divisor != null && !divisor.equals(BigDecimal.ZERO)) {
    operand = operand.divide(divisor, RoundingMode.HALF_UP);
return operand;