Example #1
0
 /**
  * Returns the difference of this Money and the given amount.
  *
  * By default, the resulting Money has the same number of fraction digits as this Money. If the result
  * cannot be represented at this scale without rounding, an exception is thrown.
  *
  * This behaviour can be overridden by providing a MoneyContext instance.
  *
  * @param Money|BigNumber|number|string $that    The amount to be subtracted.
  * @param MoneyContext|null             $context An optional scale & rounding context.
  *
  * @return Money
  *
  * @throws ArithmeticException       If the argument is an invalid number.
  * @throws CurrencyMismatchException If the argument is a money in a different currency.
  */
 public function minus($that, MoneyContext $context = null)
 {
     if ($context === null) {
         $context = new RetainContext(RoundingMode::UNNECESSARY);
     }
     $amount = $this->amount->minus($this->handleMoney($that));
     $amount = $context->applyTo($amount, $this->currency, $this->amount->scale());
     return new Money($amount, $this->currency);
 }