subtract two double values - Java java.lang

Java examples for java.lang:double

Description

subtract two double values

Demo Code


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

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

    public static double sub(double minuend, double subtrahend) {
        BigDecimal b1 = new BigDecimal(Double.toString(minuend));
        BigDecimal b2 = new BigDecimal(Double.toString(subtrahend));
        return b1.subtract(b2).doubleValue();

    }
}

Related Tutorials