multiply two double values - Java java.lang

Java examples for java.lang:double

Description

multiply two double values

Demo Code


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

public class Main {
    public static void main(String[] argv) throws Exception {
        double multiplicand = 2.45678;
        double multiplier = 2.45678;
        System.out.println(mul(multiplicand, multiplier));
    }//from  w  ww .  j a  v a 2s  .com

    public static double mul(double multiplicand, double multiplier) {
        BigDecimal b1 = new BigDecimal(Double.toString(multiplicand));
        BigDecimal b2 = new BigDecimal(Double.toString(multiplier));
        return b1.multiply(b2).doubleValue();
    }
}

Related Tutorials