Java BigDecimal Equal isEqual(BigDecimal n1, BigDecimal n2, int precision)

Here you can find the source of isEqual(BigDecimal n1, BigDecimal n2, int precision)

Description

Checks two BigDecimal with given precision - number of nulls after point.

License

Open Source License

Declaration

public static boolean isEqual(BigDecimal n1, BigDecimal n2, int precision) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;

public class Main {
    /**//  ww w.jav  a  2  s.c  o  m
     * Checks two BigDecimal with given precision - number of nulls after point. 
     * 
     * @return
     */
    public static boolean isEqual(BigDecimal n1, BigDecimal n2, int precision) {
        BigDecimal alpha = BigDecimal.ONE.movePointLeft(precision);
        return n1.subtract(n2).abs().compareTo(alpha) <= 0;
    }
}

Related

  1. Equals(BigDecimal one, BigDecimal two)
  2. equals(final BigDecimal b0, final BigDecimal b1, final double delta)
  3. equals(final BigDecimal pValue1, final BigDecimal pValue2)
  4. equalsBigDecimal(BigDecimal bd1, BigDecimal bd2)
  5. isEqual(BigDecimal aLhs, BigDecimal aRhs)
  6. isEqual(BigDecimal value1, BigDecimal value2)
  7. isEqual(final BigDecimal value1, final BigDecimal value2)
  8. isEqualsToZero(BigDecimal value)