Java BigDecimal Value Check isSameValue(final BigDecimal val1, final BigDecimal val2)

Here you can find the source of isSameValue(final BigDecimal val1, final BigDecimal val2)

Description

is Same Value

License

Apache License

Return

true if val1 == val2 (ignoring scale and null are treated as 0)

Declaration

public static boolean isSameValue(final BigDecimal val1, final BigDecimal val2) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.math.BigDecimal;

public class Main {
    /**/*from   w ww .  j a va 2 s  .co m*/
     * @return true if val1 == val2 (ignoring scale and null are treated as 0)
     */
    public static boolean isSameValue(final BigDecimal val1, final BigDecimal val2) {
        return val1 == null && val2 == null || val1 != null && val2 != null && val1.compareTo(val2) == 0;
    }

    /**
     * @return 1 if v1 > v2 or v2==null and v2!=null
     * @return 0 if v1 == v2 or v1==null and v2==null
     * @return -1 if v1 < v2 or v1==null and v2!=null
     */
    public static int compareTo(final BigDecimal v1, final BigDecimal v2) {
        int ret = 1;
        if (v1 != null && v2 != null) {
            ret = v1.compareTo(v2);
        } else if (v1 == null && v2 == null) {
            ret = 0;
        } else if (v1 == null) {
            ret = -1;
        }
        return ret;
    }
}

Related

  1. isParseableBigDecimal(String string)
  2. isPositive(BigDecimal number)
  3. isPositive(BigDecimal value)
  4. isPrimeNumber(BigDecimal inBd)
  5. isProfitable(BigDecimal ask, BigDecimal bid, BigDecimal fee, BigDecimal minProfit)
  6. isStrictementNegatif(BigDecimal pNombre)
  7. isUnscaledValueEqualsOriginal(BigDecimal bigDecimal, BigInteger bigInteger)
  8. isValidDecimal(BigDecimal bd)
  9. isValidLongitude(BigDecimal value)