Java BigDecimal Compare compareTo(final BigDecimal v1, final BigDecimal v2)

Here you can find the source of compareTo(final BigDecimal v1, final BigDecimal v2)

Description

compare To

License

Apache License

Return

-1 if v1 < v2 or v1==null and v2!=null

Declaration

public static int compareTo(final BigDecimal v1, final BigDecimal v2) 

Method Source Code


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

import java.math.BigDecimal;

public class Main {
    /**/*w ww.j a  va  2  s  .c  o m*/
     * @return 1 if v1 &gt; v2 or v2==null and v2!=null
     * @return 0 if v1 == v2 or v1==null and v2==null
     * @return -1 if v1 &lt; 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. compare(BigDecimal v1, BigDecimal v2)
  2. compareBigDecimal(BigDecimal bigDecimal, BigDecimal bigDecimal2, boolean desc)
  3. compareBigDecimals(java.math.BigDecimal one, java.math.BigDecimal two)
  4. compareTo(BigDecimal b1, BigDecimal b2)
  5. compareTo(final BigDecimal b0, final BigDecimal b1)
  6. compareToOne(BigDecimal x)
  7. compareToZeroOrNull(BigDecimal value)
  8. greaterThan(BigDecimal decimal, double number)
  9. GreaterThan(BigDecimal one, BigDecimal two)