Java BigDecimal Min min(final BigDecimal bd1, final BigDecimal bd2)

Here you can find the source of min(final BigDecimal bd1, final BigDecimal bd2)

Description

Selects the lower of two BigDecimals, preferring the non-null value if one is null.

License

Open Source License

Parameter

Parameter Description
bd1 First value.
bd2 Second value.

Return

Min of the two values or the non-null reference or null if both inputs are null.

Declaration

public static BigDecimal min(final BigDecimal bd1, final BigDecimal bd2) 

Method Source Code


//package com.java2s;
/* Copyright (c) 2011-2014 Pushing Inertia
 * All rights reserved.  http://pushinginertia.com
 *
 * Licensed 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./*from w  w  w. java2 s.co m*/
 */

import java.math.BigDecimal;

public class Main {
    /**
     * Selects the lower of two BigDecimals, preferring the non-null value if one is null.
     * @param bd1 First value.
     * @param bd2 Second value.
     * @return Min of the two values or the non-null reference or null if both inputs are null.
     */
    public static BigDecimal min(final BigDecimal bd1, final BigDecimal bd2) {
        if (bd1 == null) {
            return bd2;
        }
        if (bd2 == null) {
            return bd1;
        }
        if (bd1.compareTo(bd2) < 0) {
            return bd1;
        }
        return bd2;
    }
}

Related

  1. min(BigDecimal a, BigDecimal b)
  2. min(BigDecimal b1, BigDecimal b2)
  3. min(BigDecimal one, BigDecimal other)
  4. min(BigDecimal... amounts)
  5. min(final BigDecimal v1, final BigDecimal v2)
  6. min(List numbers)
  7. minimum(BigDecimal... decimals)
  8. minimum(BigDecimal... values)