multiply two double - Java java.lang

Java examples for java.lang:double

Description

multiply two double

Demo Code


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

public class Main {
    public static void main(String[] argv) throws Exception {
        double d1 = 2.45678;
        double d2 = 2.45678;
        System.out.println(mul(d1, d2));
    }/*from   w  w  w . j  a  v  a 2  s.  co  m*/

    public static double mul(double d1, double d2) {
        BigDecimal bd1 = new BigDecimal(Double.toString(d1));
        BigDecimal bd2 = new BigDecimal(Double.toString(d2));
        return bd1.multiply(bd2).doubleValue();
    }
}

Related Tutorials