Java BigDecimal Divide divide(BigDecimal amount, BigDecimal divisor)

Here you can find the source of divide(BigDecimal amount, BigDecimal divisor)

Description

divide

License

Open Source License

Declaration

public static BigDecimal divide(BigDecimal amount, BigDecimal divisor) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main {
    public static BigDecimal divide(BigDecimal amount, BigDecimal divisor) {
        return roundBigDecimal(amount.divide(divisor, 2, RoundingMode.HALF_UP));
    }/*from  ww w  .java  2  s .com*/

    public static BigDecimal divide(BigDecimal amount, BigDecimal divisor, int scale) {
        return amount.divide(divisor, scale, RoundingMode.HALF_UP);
    }

    public static BigDecimal roundBigDecimal(BigDecimal num) {
        return roundBigDecimal(num, 2);
    }

    public static BigDecimal roundBigDecimal(BigDecimal num, int scale) {
        if (num != null) {
            return num.setScale(scale, RoundingMode.HALF_UP);
        }
        return num;
    }
}

Related

  1. div(BigDecimal b1, BigDecimal b2)
  2. div(BigDecimal d1, BigDecimal d2)
  3. div(BigDecimal v1, BigDecimal v2)
  4. div(BigDecimal val, long divisor)
  5. divide(BigDecimal a, BigDecimal b)
  6. divide(BigDecimal aValue1, BigDecimal aValue2, int scale)
  7. divide(BigDecimal bd1, BigDecimal bd2)
  8. divide(BigDecimal dividend, BigDecimal divisor)
  9. divide(BigDecimal dividend, BigDecimal divisor)