예제 #1
0
파일: Money.php 프로젝트: brick/money
 /**
  * Returns a copy of this Money converted into another currency.
  *
  * By default, the scale of the result is adjusted to represent the exact converted value.
  * For example, converting `USD 1.23` to `EUR` with an exchange rate of `0.91` will yield `USD 1.1193`.
  * The scale can be specified by providing a `MoneyContext` instance.
  *
  * @param Currency|string         $currency       The target currency or currency code.
  * @param BigNumber|number|string $exchangeRate   The exchange rate to multiply by.
  * @param MoneyContext|null       $context        An optional context for scale & rounding.
  *
  * @return Money
  *
  * @throws UnknownCurrencyException If an unknown currency code is given.
  * @throws ArithmeticException      If the exchange rate or rounding mode is invalid, or rounding is necessary.
  */
 public function convertedTo($currency, $exchangeRate, MoneyContext $context = null)
 {
     $currency = Currency::of($currency);
     if ($context === null) {
         $context = new ExactContext();
     }
     $amount = $this->amount->toBigRational()->multipliedBy($exchangeRate);
     $amount = $context->applyTo($amount, $currency, $this->amount->scale());
     return new Money($amount, $currency);
 }