Java Number Divide div(double v1, double v2)

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

Description

div

License

Apache License

Declaration

public static double div(double v1, double v2) 

Method Source Code


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

import java.math.BigDecimal;

public class Main {
    public static double div(double v1, double v2, int scale) {
        if (scale < 0) {
            throw new IllegalArgumentException("The scale must be a positive integer or zero");
        }/*  w  w  w  .j  a  va 2 s .  com*/
        BigDecimal b1 = new BigDecimal(Double.toString(v1));
        BigDecimal b2 = new BigDecimal(Double.toString(v2));
        return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    public static double div(double v1, double v2) {
        BigDecimal b1 = new BigDecimal(Double.toString(v1));
        BigDecimal b2 = new BigDecimal(Double.toString(v2));
        return b1.divide(b2, 0, BigDecimal.ROUND_DOWN).doubleValue();
    }
}

Related

  1. div(Class clazz, T a, T b)
  2. div(double a, double b, int len)
  3. div(double operand1, double operand2)
  4. div(Double v1, Double v2)
  5. div(Double v1, Double v2)
  6. div(double v1, double v2)
  7. div(double v1, double v2, int scale)
  8. div(long v1, long v2)