Java BigDecimal Subtract sub(BigDecimal b1, BigDecimal b2)

Here you can find the source of sub(BigDecimal b1, BigDecimal b2)

Description

Substract @param b1 with @param b2

License

Open Source License

Parameter

Parameter Description
b1 <code>java.math.BigDecimal</code>
b2 <code>java.math.BigDecimal</code>

Return

substract result

Declaration

public static BigDecimal sub(BigDecimal b1, BigDecimal b2) 

Method Source Code


//package com.java2s;
/*/*w  ww . jav  a 2  s .  com*/
 * File: $RCSfile$
 *
 * Copyright (c) 2005 Wincor Nixdorf International GmbH,
 * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of Wincor Nixdorf ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered
 * into with Wincor Nixdorf.
 */

import java.math.BigDecimal;

public class Main {
    /**
     * Substract @param v1 with @param v2
     *
     * @param v1 <code>Integer</code>
     * @param v2 <code>Integer</code>
     * @return substract result
     */
    public static Integer sub(Integer v1, Integer v2) {
        if (v1 == null && v2 == null) {
            return null;
        }
        if (v1 == null) {
            v1 = new Integer(0);
        }
        if (v2 == null) {
            v2 = new Integer(0);
        }
        return new Integer(v1.intValue() - v2.intValue());

    }

    /**
     * Substract @param a1 with @param a2
     *
     * @param v1 <code>double</code>
     * @param v2 <code>double</code>
     * @return substract result
     */
    public static double sub(double v1, double v2) {
        BigDecimal b1 = new BigDecimal(Double.toString(v1));
        BigDecimal b2 = new BigDecimal(Double.toString(v2));
        return b1.subtract(b2).doubleValue();
    }

    /**
     * Substract @param b1 with @param b2
     *
     * @param b1 <code>java.math.BigDecimal</code>
     * @param b2 <code>java.math.BigDecimal</code>
     * @return substract result
     */
    public static BigDecimal sub(BigDecimal b1, BigDecimal b2) {
        if (b1 == null && b2 == null) {
            return null;
        }
        if (b1 == null) {
            b1 = new BigDecimal(0);
        }
        if (b2 == null) {
            b2 = new BigDecimal(0);
        }
        return b1.subtract(b2);
    }
}

Related

  1. sub(BigDecimal d1, BigDecimal d2)
  2. sub(BigDecimal v1, BigDecimal v2)
  3. sub(BigDecimal v1, BigDecimal v2)
  4. subtract(BigDecimal a, BigDecimal b)