add two double values - Java java.lang

Java examples for java.lang:double

Description

add two double values

Demo Code


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

public class Main {
    public static void main(String[] argv) throws Exception {
        double summand = 2.45678;
        double addend = 2.45678;
        System.out.println(add(summand, addend));
    }/*from  w  ww.  j  a v  a 2  s  .  c o  m*/

    public static double add(double summand, double addend) {
        BigDecimal bd1 = new BigDecimal(Double.toString(addend));
        BigDecimal bd2 = new BigDecimal(Double.toString(summand));
        return bd1.add(bd2).doubleValue();

    }
}

Related Tutorials