Java BigDecimal Compare compareTo(BigDecimal b1, BigDecimal b2)

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

Description

Compare to b1 with b2

License

Open Source License

Parameter

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

Return

if b1 and b2 ==null return 0, else @see java.math.BigDecimal#compareTo

Declaration

public static int compareTo(BigDecimal b1, BigDecimal b2) 

Method Source Code


//package com.java2s;
/*//  ww w  . j av a2s.c o  m
 * 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 {
    public static final BigDecimal ZERO = new BigDecimal((double) 0);

    /**
     * Compare to b1 with b2
     *
     * @param b1 <code>java.math.BigDecimal</code>
     * @param b2 <code>java.math.BigDecimal</code>
     * @return if b1 and b2 ==null return 0, else @see java.math.BigDecimal#compareTo
     */
    public static int compareTo(BigDecimal b1, BigDecimal b2) {
        if (b1 == null && b2 == null) {
            return 0;
        }
        if (b1 == null) {
            b1 = ZERO;
        }
        if (b2 == null) {
            b2 = ZERO;
        }
        return b1.compareTo(b2);
    }
}

Related

  1. compare(BigDecimal first, BigDecimal second)
  2. compare(BigDecimal one, BigDecimal other)
  3. compare(BigDecimal v1, BigDecimal v2)
  4. compareBigDecimal(BigDecimal bigDecimal, BigDecimal bigDecimal2, boolean desc)
  5. compareBigDecimals(java.math.BigDecimal one, java.math.BigDecimal two)
  6. compareTo(final BigDecimal b0, final BigDecimal b1)
  7. compareTo(final BigDecimal v1, final BigDecimal v2)
  8. compareToOne(BigDecimal x)
  9. compareToZeroOrNull(BigDecimal value)