Java Number Add add(double v1, double v2)

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

Description

add

License

Open Source License

Declaration

public static double add(double v1, double v2) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;

public class Main {
    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();
    }/*  ww w . j  a  v a2s .c o  m*/

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

    public static String toString(Object object, String defaultvalue) {
        if (object == null) {
            return defaultvalue;
        }
        if (object instanceof String) {
            return (String) object;
        }
        return object.toString();
    }

    public static String toString(Object[] obj) {
        if (obj == null) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < obj.length; i++) {
            sb.append(obj[i]);
            if (i < obj.length - 1) {
                sb.append(",");
            }
        }
        return sb.toString();
    }
}

Related

  1. add(double v1, double v2)
  2. add(Double v1, Double v2)
  3. add(double v1, double v2)
  4. add(Double v1, Double v2)
  5. add(double v1, double v2)
  6. add(Double v1, Double v2)
  7. add(double... ds)
  8. add(Double... ds)
  9. add(final Number a, final Number b)