Java BigDecimal Divide divide(BigDecimal num1, BigDecimal num2, int scale, int roundingMode)

Here you can find the source of divide(BigDecimal num1, BigDecimal num2, int scale, int roundingMode)

Description

divide

License

Apache License

Declaration

public static BigDecimal divide(BigDecimal num1, BigDecimal num2, int scale, int roundingMode) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.math.BigDecimal;

public class Main {
    public static final int STANDARD_ROUND_HALF = BigDecimal.ROUND_HALF_UP;
    public static final int STANDARD_SCALE = 2;
    /**//www  . ja v  a 2  s .  co  m
     * 0
     **/
    public static final BigDecimal ZERO = new BigDecimal("0");

    public static BigDecimal divide(BigDecimal num1, BigDecimal num2, int scale, int roundingMode) {
        if (null == num1 || null == num2) {
            return ZERO;
        }
        if (num2.compareTo(ZERO) == 0) {
            return ZERO;
        }
        return num1.divide(num2, STANDARD_SCALE, STANDARD_ROUND_HALF);
    }
}

Related

  1. divide(BigDecimal dividend, BigDecimal divisor)
  2. divide(BigDecimal dividend, BigDecimal divisor)
  3. divide(BigDecimal dividend, BigDecimal divisor, int scale)
  4. divide(BigDecimal left, BigDecimal right)
  5. divide(BigDecimal num1, BigDecimal num2, int scale, int mode)
  6. divide(BigDecimal number1, BigDecimal number2, int decimalPlaces)
  7. divide(BigDecimal numerator, BigDecimal denominator)
  8. divide(BigDecimal one, BigDecimal another)
  9. divide(BigDecimal op1, int op2, int precision)