コード例 #1
0
ファイル: Converter.php プロジェクト: squigg/money
 /**
  * @param Money    $money
  * @param Currency $counterCurrency
  * @param int      $roundingMode
  *
  * @return Money
  */
 public function convert(Money $money, Currency $counterCurrency, $roundingMode = Money::ROUND_HALF_UP)
 {
     $baseCurrency = $money->getCurrency();
     $ratio = $this->exchange->quote($baseCurrency, $counterCurrency)->getConversionRatio();
     $baseCurrencySubunit = $this->currencies->subunitFor($baseCurrency);
     $counterCurrencySubunit = $this->currencies->subunitFor($counterCurrency);
     $subunitDifference = $baseCurrencySubunit - $counterCurrencySubunit;
     $ratio = $ratio / pow(10, $subunitDifference);
     $counterValue = $money->multiply($ratio, $roundingMode);
     return new Money($counterValue->getAmount(), $counterCurrency);
 }
コード例 #2
0
ファイル: MoneyTest.php プロジェクト: erictho/money
 /**
  * @covers            \SebastianBergmann\Money\Money::multiply
  * @uses              \SebastianBergmann\Money\Money::__construct
  * @uses              \SebastianBergmann\Money\Money::handleCurrencyArgument
  * @uses              \SebastianBergmann\Money\Currency
  * @expectedException \SebastianBergmann\Money\InvalidArgumentException
  */
 public function testExceptionIsRaisedWhenMultipliedUsingInvalidRoundingMode()
 {
     $a = new Money(1, new Currency('EUR'));
     $a->multiply(2, null);
 }