Java BigDecimal Add add(BigDecimal a, BigDecimal b)

Here you can find the source of add(BigDecimal a, BigDecimal b)

Description

add two bigdecimal number.

License

Apache License

Parameter

Parameter Description
a a parameter
b a parameter

Declaration

public static BigDecimal add(BigDecimal a, BigDecimal b) 

Method Source Code


//package com.java2s;
/*//from w  w w  .j  a v  a2 s . c om
 * Copyright [2011] [C.H Li http://code.google.com/p/idocbox-common/]
 * Licensed to the Chunhui Li(C.H Li) under one or more contributor license agreements.  
 * See the NOTICE file distributed with this work for additional information 
 * regarding copyright ownership.
 *
 * C.H Li licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.math.BigDecimal;

public class Main {
    /**
     * add two bigdecimal number.
     * @param a
     * @param b
     * @return
     */
    public static BigDecimal add(BigDecimal a, BigDecimal b) {
        BigDecimal c = new BigDecimal(0);

        if (null != a) {
            c = c.add(a);
        }
        if (null != b) {
            c = c.add(b);
        }

        return c;
    }

    /**
     * add bigdecimal with double.
     * @param a
     * @param b
     * @return
     */
    public static BigDecimal add(BigDecimal a, Double b) {
        BigDecimal bb = null;
        if (null != b) {
            bb = new BigDecimal(b);
        }
        return add(a, bb);
    }
}

Related

  1. add(BigDecimal a, BigDecimal b)
  2. add(BigDecimal a, BigDecimal b)
  3. add(BigDecimal aValue1, BigDecimal aValue2)
  4. add(BigDecimal bigDecimal, BigDecimal bigDecimal2)
  5. add(BigDecimal left, BigDecimal right)