Litipk\BigNumbers\Decimal::equals PHP Method

equals() public method

Equality comparison between this object and $b
public equals ( Decimal $b, integer $scale = null ) : boolean
$b Decimal
$scale integer
return boolean
    public function equals(Decimal $b, $scale = null)
    {
        self::paramsValidation($b, $scale);
        if ($this === $b) {
            return true;
        } elseif ($b->isInfinite()) {
            return false;
        } else {
            $cmp_scale = $scale !== null ? $scale : max($this->scale, $b->scale);
            return bccomp(self::innerRound($this->value, $cmp_scale), self::innerRound($b->value, $cmp_scale), $cmp_scale) == 0;
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Checks whether the value represented by this object equals to the other
  *
  * @param Money $money
  * @return bool
  */
 public function equals(Money $money)
 {
     return $this->isSameCurrency($money) && $this->amount->equals($money->amount, $this->getInnerPrecision());
 }