Java Double Number Divide divideNumber(Object divisor, Object dividend)

Here you can find the source of divideNumber(Object divisor, Object dividend)

Description

divide Number

License

Apache License

Declaration

public static String divideNumber(Object divisor, Object dividend) 

Method Source Code


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

import java.math.BigDecimal;

public class Main {

    public static String divideNumber(Object divisor, Object dividend) {
        if (divisor == null || dividend == null) {
            return "";
        }//ww  w .j  a v a  2  s. c o  m
        BigDecimal a = toBig(divisor);
        BigDecimal b = toBig(dividend);
        if (a.equals(toBig(0)) || b.equals(toBig(0))) {
            return "0";
        }
        BigDecimal c = a.divide(b, 2, BigDecimal.ROUND_DOWN);
        return c.toString();
    }

    public static BigDecimal toBig(Object o) {
        if (o == null || o.toString().equals("") || o.toString().equals("NaN")) {
            return new BigDecimal(0);
        }
        return new BigDecimal(o.toString());
    }
}

Related

  1. divide4Money(Double value1, Double value2)
  2. divideComplex(double realOne, double imagOne, double realTwo, double imagTwo)
  3. divideDouble(double first, double second)
  4. divideDouble(double first, double second, int scale, int roundingMode)
  5. divideInts(int numerator, int denominator)
  6. divZ(double z)
  7. getIntDividedCeil(final int nDividend, final int nDivisor)
  8. getLongDivided(final long nDividend, final long nDivisor, @Nonnull final RoundingMode eRoundingMode)
  9. roundDivide(double[] dividend, double[] divisor, int scale)