Skip to content

Commit

Permalink
close #22 Fixed: Convert function rate issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Feb 1, 2019
1 parent 5c7cdc1 commit 16ec48b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,16 @@ public function lessThanOrEqual(self $other)
*/
public function convert(Currency $currency, $ratio, $roundingMode = self::ROUND_HALF_UP)
{
$this->currency = $currency;

$this->assertOperand($ratio);
$this->assertRoundingMode($roundingMode);

return new self(round($this->amount * $ratio, $this->currency->getPrecision(), $roundingMode), $currency);
if ($ratio < 1) {
return $this->divide($ratio, $roundingMode);
}

return $this->multiply($ratio, $roundingMode);
}

/**
Expand Down Expand Up @@ -581,7 +587,7 @@ public function subtract(self $subtrahend)
*/
public function multiply($multiplier, $roundingMode = self::ROUND_HALF_UP)
{
return $this->convert($this->currency, $multiplier, $roundingMode);
return new self(round($this->amount * $multiplier, $this->currency->getPrecision(), $roundingMode), $this->currency);
}

/**
Expand Down

0 comments on commit 16ec48b

Please sign in to comment.