Java Double Number Divide divide(String num1, String num2, int scale)

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

Description

divide

License

Apache License

Declaration

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

Method Source Code


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

import java.math.BigDecimal;

public class Main {

    public static BigDecimal divide(String num1, String num2, int scale) {
        num1 = checkNum(num1);// ww w .j a  v a 2  s.  c  om
        if ("".equals(num2)) {
            num2 = "1";
        }
        BigDecimal bd1 = new BigDecimal(num1);
        BigDecimal bd2 = new BigDecimal(num2);
        return bd1.divide(bd2, scale, BigDecimal.ROUND_HALF_UP);
    }

    private static String checkNum(String num) {
        if ("".equals(num)) {
            num = "0";
        }
        return num;
    }
}

Related

  1. divide(float left, float right)
  2. divide(Number numerator, Number denominator)
  3. divide(Object dividend, Object divisor)
  4. divide(Object num1, Object num2)
  5. divide(String num1, String num2)
  6. divide(String num1, String num2, int scale)
  7. divide(String thisVal, String addVal)
  8. divide4Money(Double value1, Double value2)
  9. divideComplex(double realOne, double imagOne, double realTwo, double imagTwo)