Java Number Add add1(Double v1, Double v2)

Here you can find the source of add1(Double v1, Double v2)

Description

add

License

Open Source License

Declaration

public static Double add1(Double v1, Double v2) 

Method Source Code


//package com.java2s;
import java.math.BigDecimal;

public class Main {

    public static Double add1(Double v1, Double v2) {
        if (v1 == null) {
            v1 = 0d;// w w  w.  j a v  a2  s .co  m
        }
        if (v2 == null) {
            v2 = 0d;
        }
        double s1 = v1, s2 = v2;
        double v = add(s1, s2);
        if (v == 0) {
            return null;
        }
        return Double.valueOf(v);
    }

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

    public static double add(Double v1, Double v2) {
        if (v1 == null) {
            v1 = 0d;
        }
        if (v2 == null) {
            v2 = 0d;
        }
        double s1 = v1, s2 = v2;
        return add(s1, s2);
    }
}

Related

  1. add(Number a, Number b)
  2. add(Object addend, Object augend)
  3. add(Object num1, Object num2)
  4. add(String number1, String number2)
  5. add(T a, T b)
  6. add4Money(Double value1, Double value2)
  7. addAmounts(final double num1, final double num2)
  8. addDoubles(Double value, Double addValue)
  9. addDoubles(String str1, String str2, int rounding)