Java BigDecimal Divide div(BigDecimal v1, BigDecimal v2)

Here you can find the source of div(BigDecimal v1, BigDecimal v2)

Description

div

License

LGPL

Declaration

public static BigDecimal div(BigDecimal v1, BigDecimal v2) 

Method Source Code


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

import java.math.BigDecimal;

public class Main {
    private static final int DEF_DIV_SCALE = 10;

    public static BigDecimal div(BigDecimal v1, BigDecimal v2) {
        return div(v1, v2, DEF_DIV_SCALE);
    }//w  w  w  . j  a  va  2 s  .  c  o  m

    public static BigDecimal div(BigDecimal v1, BigDecimal v2, int scale) {
        if (scale < 0) {
            throw new IllegalArgumentException("The scale must be a positive integer or zero");
        }
        BigDecimal b1 = new BigDecimal(Double.toString(v1.doubleValue()));
        BigDecimal b2 = new BigDecimal(Double.toString(v2.doubleValue()));
        return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP);
    }
}

Related

  1. decimalDivide(BigDecimal cs, BigDecimal bcs, int scale)
  2. div(BigDecimal b1, BigDecimal b2)
  3. div(BigDecimal d1, BigDecimal d2)
  4. div(BigDecimal val, long divisor)
  5. divide(BigDecimal a, BigDecimal b)
  6. divide(BigDecimal amount, BigDecimal divisor)
  7. divide(BigDecimal aValue1, BigDecimal aValue2, int scale)