Exemple #1
0
 /**
  * @param \Money\Money $money
  * @param        $rounding_mode
  * @return \Money\Money
  * @expectedException InvalidArgumentException
  */
 public function convert(Money $money, RoundingMode $rounding_mode = null)
 {
     if (!$money->getCurrency()->equals($this->baseCurrency)) {
         throw new InvalidArgumentException("The Money has the wrong currency");
     }
     $rounding_mode = $rounding_mode ?: RoundingMode::halfUp();
     return new Money((int) round($money->getAmount() * $this->ratio, 0, $rounding_mode->getRoundingMode()), $this->counterCurrency);
 }
Exemple #2
0
 /**
  * @param $divisor
  * @param int|\Money\RoundingMode $rounding_mode
  * @return Money
  */
 public function divide($divisor, $rounding_mode = self::ROUND_HALF_UP)
 {
     $this->assertOperand($divisor);
     if (!$rounding_mode instanceof RoundingMode) {
         $rounding_mode = new RoundingMode($rounding_mode);
     }
     $quotient = (int) round($this->amount / $divisor, 0, $rounding_mode->getRoundingMode());
     return new Money($quotient, $this->currency);
 }
Exemple #3
0
 /**
  * @test
  */
 public function Get()
 {
     $rounding_mode = new RoundingMode(RoundingMode::ROUND_HALF_DOWN);
     $this->assertEquals(RoundingMode::ROUND_HALF_DOWN, $rounding_mode->getRoundingMode());
 }