multiply two double via BigDecimal - Java java.math

Java examples for java.math:BigDecimal Calculation

Description

multiply two double via BigDecimal

Demo Code


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

public class Main {
    public static void main(String[] argv) throws Exception {
        double v1 = 2.45678;
        double v2 = 2.45678;
        System.out.println(mul(v1, v2));
    }/*from  w  w w.jav  a 2 s.  c  om*/

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

Related Tutorials