示例#1
0
 public function addMoney(Money $m)
 {
     if ($this->currency() == $m->currency()) {
         return new Money($this->amount() + $m->amount(), $this->currency());
     }
     return MoneyBag::create($this, $m);
 }
示例#2
0
文件: Money.php 项目: kanunak/money
 /**
  * @param Money $money
  * @return bool
  */
 private function isSameCurrency(Money $money)
 {
     return $this->currency()->equals($money->currency());
 }
示例#3
0
 private function contains(Money $m)
 {
     $found = $this->findMoney($m->currency());
     if ($found == NULL) {
         return FALSE;
     }
     return $found->amount() == $m->amount();
 }
示例#4
0
 public function equals(Money $money) : bool
 {
     return $this->currency->equals($money->currency()) && $this->amount === $money->amount();
 }
示例#5
0
文件: money.php 项目: jaz303/base-php
 public function convert(Money $m, $to_currency, $round = 'down')
 {
     $factor = $this->get_factor($m->currency(), $to_currency);
     if ($factor === null) {
         throw new MoneyConversionException("no conversion for {$m->currency()} -> {$to_currency}");
     }
     $units = Money::round($m->units() * $factor, $round);
     return new Money($units, $to_currency);
 }
示例#6
0
 public function isLessThan(Money $money) : bool
 {
     $this->ensureCurrenciesMatch($this->currency, $money->currency());
     return $this->amount < $money->amount();
 }