Java BigDecimal Equal isEqual(final BigDecimal value1, final BigDecimal value2)

Here you can find the source of isEqual(final BigDecimal value1, final BigDecimal value2)

Description

Compares two given BigDecimals.

License

Open Source License

Parameter

Parameter Description
value1 a parameter
value2 a parameter

Declaration

public static boolean isEqual(final BigDecimal value1, final BigDecimal value2) 

Method Source Code


//package com.java2s;
// ProjectForge is dual-licensed.

import java.math.BigDecimal;

public class Main {
    /**/*w  ww . j a  v  a2  s.c  om*/
     * Compares two given BigDecimals. They are equal if the value is equal independent of the scale (5.70 is equals to 5.7 and null is equals
     * null, but null is not equals to 0).
     * @param value1
     * @param value2
     * @return
     * @see BigDecimal#compareTo(BigDecimal)
     */
    public static boolean isEqual(final BigDecimal value1, final BigDecimal value2) {
        if (value1 == null) {
            return (value2 == null) ? true : false;
        }
        if (value2 == null) {
            return false;
        }
        return value1.compareTo(value2) == 0;
    }

    /**
     * Compares two given Integers using compareTo method.
     * @param value1
     * @param value
     * @return
     * @see Integer#compareTo(Integer)
     */
    public static boolean isEqual(final Integer value1, final Integer value) {
        if (value1 == null) {
            return (value == null) ? true : false;
        }
        if (value == null) {
            return false;
        }
        return value1.compareTo(value) == 0;
    }
}

Related

  1. equals(final BigDecimal pValue1, final BigDecimal pValue2)
  2. equalsBigDecimal(BigDecimal bd1, BigDecimal bd2)
  3. isEqual(BigDecimal aLhs, BigDecimal aRhs)
  4. isEqual(BigDecimal n1, BigDecimal n2, int precision)
  5. isEqual(BigDecimal value1, BigDecimal value2)
  6. isEqualsToZero(BigDecimal value)