Money\Money::subtract PHP Method

subtract() public method

Returns a new Money object that represents the difference of this and another Money object
public subtract ( Money $subtrahend ) : Money
$subtrahend Money
return Money
    public function subtract(Money $subtrahend)
    {
        $this->assertSameCurrencyAs($subtrahend);
        $amount = bcsub($this->amount, $subtrahend->amount, self::SCALE);
        return $this->newInstance($amount);
    }

Usage Example

Example #1
0
 /**
  * Decrease this account current balance
  *
  * @param Money $amount
  * @throws InsufficientFunds
  *     A member cannot withdraw more than it's account current balance
  */
 public function withdraw(Money $amount)
 {
     if ($amount->greaterThan($this->balance)) {
         throw new InsufficientFunds("Cannot withdraw {$amount->getAmount()}");
     }
     $this->balance = $this->balance->subtract($amount);
 }
All Usage Examples Of Money\Money::subtract