Litipk\BigNumbers\Decimal::add PHP Method

add() public method

Adds two Decimal objects
public add ( Decimal $b, integer $scale = null ) : Decimal
$b Decimal
$scale integer
return Decimal
    public function add(Decimal $b, $scale = null)
    {
        self::paramsValidation($b, $scale);
        if ($b->isInfinite()) {
            return $b;
        }
        return self::fromString(bcadd($this->value, $b->value, max($this->scale, $b->scale)), $scale);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Returns a new Money object that represents
  * the sum of this and an other Money object
  *
  * @param Money $money
  * @return Money
  */
 public function add(Money $money)
 {
     $this->assertSameCurrency($money);
     $amount = $this->amount->add($money->amount, $this->getInnerPrecision());
     return $this->newInstance($amount);
 }