當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Money::getCurrency方法代碼示例

本文整理匯總了PHP中Money::getCurrency方法的典型用法代碼示例。如果您正苦於以下問題:PHP Money::getCurrency方法的具體用法?PHP Money::getCurrency怎麽用?PHP Money::getCurrency使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Money的用法示例。


在下文中一共展示了Money::getCurrency方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: convert

 /**
  * Converts Money from base to counter currency.
  *
  * @param Money $money
  * @param int   $roundingMode
  *
  * @return Money
  *
  * @throws \InvalidArgumentException If $money's currency is not equal to base currency
  */
 public function convert(Money $money, $roundingMode = Money::ROUND_HALF_UP)
 {
     if (!$money->getCurrency()->equals($this->baseCurrency)) {
         throw new \InvalidArgumentException('The Money has the wrong currency');
     }
     return $money->convert($this->counterCurrency, $this->conversionRatio, $roundingMode);
 }
開發者ID:barryvdh,項目名稱:money,代碼行數:17,代碼來源:CurrencyPair.php

示例2: add

 /**
  * @param money $amount
  * @return money
  */
 public function add(Money $amount)
 {
     if (!$this->currency->equals($amount->getCurrency())) {
         throw new \InvalidArgumentException('Currency mismatch');
     }
     return new Money($this->currency, $this->amount + $amount->getValue());
 }
開發者ID:rocketpastsix,項目名稱:OOPExample,代碼行數:11,代碼來源:money.php

示例3: convert

 /** @return Money */
 public function convert(Money $money)
 {
     if (!$money->getCurrency()->equals($this->counterCurrency)) {
         throw new InvalidArgumentException("The Money has the wrong currency");
     }
     // @todo add rounding mode?
     return new Money((int) round($money->getAmount() * $this->ratio), $this->baseCurrency);
 }
開發者ID:SerdarSanri,項目名稱:laravel-money,代碼行數:9,代碼來源:CurrencyPair.php

示例4: convert

 /**
  * @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);
 }
開發者ID:squigg,項目名稱:money,代碼行數:18,代碼來源:Converter.php

示例5: subtract

 /**
  * Subtratcs the given money from this one (immutable) and returns the result.
  *
  * @param Money $money the money to subtract
  *
  * @return Money
  *
  * @throws CurrencyMismatchException if the Currencies do not match
  */
 public function subtract(Money $money)
 {
     if (!$this->currency->equals($money->getCurrency())) {
         throw new CurrencyMismatchException($this . ' does not match ' . $money);
     }
     $amount = bcsub($this->amount, $money->getAmount(), self::BCSCALE);
     return self::valueOf($amount, $this->currency);
 }
開發者ID:supremenewmedia,項目名稱:finance,代碼行數:17,代碼來源:Money.php

示例6: compareCurrency

 /**
  * @param Money $otherMoney
  *
  * @throws CurrencyMismatchException
  */
 private function compareCurrency(Money $otherMoney)
 {
     if ($this->currency->compareTo($otherMoney->getCurrency()) !== 0) {
         throw CurrencyMismatchException::currenciesNotMatching($this->currency->getCode(), $otherMoney->getCurrency()->getCode());
     }
 }
開發者ID:jonasdekeukelaere,項目名稱:money,代碼行數:11,代碼來源:Money.php

示例7: testSetValueAsMoney

 function testSetValueAsMoney()
 {
     $m1 = new Money();
     $m1->setValue(array('Currency' => 'EUR', 'Amount' => 3.44));
     $m2 = new Money();
     $m2->setValue($m1);
     $this->assertEquals($m2->getCurrency(), 'EUR');
     $this->assertEquals($m2->getAmount(), 3.44);
 }
開發者ID:SustainableCoastlines,項目名稱:loveyourwater,代碼行數:9,代碼來源:MoneyTest.php

示例8: testCurrencyCanBeReturned

 public function testCurrencyCanBeReturned()
 {
     $currency = new USD();
     $money = new Money($currency, 1);
     $this->assertEquals($currency, $money->getCurrency());
 }
開發者ID:rocketpastsix,項目名稱:OOPExample,代碼行數:6,代碼來源:moneyTest.php

示例9: compareTo

 /**
  * Compares this instance with an other instance.
  *
  * @param Money $b The instance to which this instance is to be compared.
  *
  * @return int -1, 0 or 1 as this instance is less than, equal to, or greater than $b
  *
  * @throws \InvalidArgumentException When the currencies do not match
  */
 public function compareTo(Money $b)
 {
     if ($this->getCurrency() != $b->getCurrency()) {
         throw new \InvalidArgumentException('Can not compare different currencies');
     }
     if ($this->getAmount() < $b->getAmount()) {
         return -1;
     } elseif ($this->getAmount() == $b->getAmount()) {
         return 0;
     } else {
         return 1;
     }
 }
開發者ID:invit,項目名稱:swiss-payment,代碼行數:22,代碼來源:Money.php

示例10: getCurrency

 /**
  * Returns the currency.
  * 
  * @return string
  */
 public function getCurrency()
 {
     $currency = parent::getCurrency();
     $this->extend('updateCurrency', $currency);
     return $currency;
 }
開發者ID:silvercart,項目名稱:silvercart,代碼行數:11,代碼來源:SilvercartMoney.php

示例11: isSameCurrencyAs

 /**
  * @param Money $money
  * @return bool
  */
 public function isSameCurrencyAs(Money $money)
 {
     return $this->currency->equals($money->getCurrency());
 }
開發者ID:superbalist,項目名稱:php-money,代碼行數:8,代碼來源:Money.php

示例12: compare

 /**
  * compare
  * 
  * Compares two instances for equality. Returns a value suitable for a sort
  * callback. i.e. 1 if $first is larger than $second, 0 if equal, and -1 if
  * $first is smaller than $second.
  * 
  * @param Money $first
  * @param Money $second
  * @return int -1, 0, or 1
  */
 public function compare(Money $first, Money $second)
 {
     $secondValue = $first->getCurrency()->getCode() === $second->getCurrency()->getCode() ? $second->getValue() : $this->converter->convert($second, $first->getCurrency())->getValue();
     return bccomp($first->getValue(), $secondValue, max([$first->getPrecision(), $second->getPrecision()]));
 }
開發者ID:mcordingley,項目名稱:money,代碼行數:16,代碼來源:Comparator.php

示例13: equalTo

 /**
  * Compare if the amount is equal to the given amount.
  *
  * @param Money $money
  * @return bool
  * @throws \InvalidArgumentException
  */
 public function equalTo(Money $money)
 {
     if ($this->getCurrency() !== $money->getCurrency()) {
         throw new \InvalidArgumentException("Argument one must be of same currency");
     }
     return $this->getAmount() === $money->getAmount();
 }
開發者ID:KasaiDot,項目名稱:XtraUpload,代碼行數:14,代碼來源:Money.php

示例14: equals

 /**
  * 等価性確認
  *
  * @param Money $money マネーオブジェクト
  * @return bool 等価性(trueで等価)
  */
 public function equals(Money $money)
 {
     return $this->_amount === $money->getAmount() && $this->_currency === $money->getCurrency();
 }
開發者ID:kazuhsat5,項目名稱:pattern,代碼行數:10,代碼來源:Money.php

示例15: assertSameCurrency

 /**
  * @param  \SebastianBergmann\Money\Money $a
  * @param  \SebastianBergmann\Money\Money $b
  * @throws \SebastianBergmann\Money\CurrencyMismatchException
  */
 private function assertSameCurrency(Money $a, Money $b)
 {
     if ($a->getCurrency() != $b->getCurrency()) {
         throw new CurrencyMismatchException();
     }
 }
開發者ID:cuongnd,項目名稱:etravelservice,代碼行數:11,代碼來源:Money.php


注:本文中的Money::getCurrency方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。