/** * @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); }
/** * @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); }