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


PHP Money類代碼示例

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


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

示例1: addMoney

 public function addMoney(Money $m)
 {
     if ($this->currency() == $m->currency()) {
         return new Money($this->amount() + $m->amount(), $this->currency());
     }
     return MoneyBag::create($this, $m);
 }
開發者ID:dalinhuang,項目名稱:shopexts,代碼行數:7,代碼來源:Money.php

示例2: 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

示例3: 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

示例4: testShouldFail

 public function testShouldFail()
 {
     $a = new Money(9);
     //$b = $a->negate();
     //$this->assertEquals(-9, $b->getAmount());
     $this->assertEquals(-8, $a->getAmount());
 }
開發者ID:redace85,項目名稱:phpunit-playground,代碼行數:7,代碼來源:MoneyTest.php

示例5: price_for_display

 public static function price_for_display($price)
 {
     $currency = ShopConfig::get_site_currency();
     $field = new Money("Price");
     $field->setAmount($price);
     $field->setCurrency($currency);
     return $field;
 }
開發者ID:helpfulrobot,項目名稱:silvershop-core,代碼行數:8,代碼來源:ShopTools.php

示例6: 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

示例7: testCanBeNegated

 public function testCanBeNegated()
 {
     // Arrange
     $a = new Money(1);
     // Act
     $b = $a->negate();
     // Assert
     $this->assertEquals(-1, $b->getAmount());
 }
開發者ID:bntptr,項目名稱:training,代碼行數:9,代碼來源:MoneyTest.php

示例8: testSubstractionResult

 public function testSubstractionResult()
 {
     // Arrange
     $a = new Money();
     // Act
     $b = $a->substraction(2, 1);
     // Assert
     $this->assertEquals(1, $b);
 }
開發者ID:ds0201,項目名稱:devci,代碼行數:9,代碼來源:MoneyTest.php

示例9: testAdd

 public function testAdd()
 {
     // Arrange
     $a = new Money(600);
     // Act
     $a->add(66);
     // Assert
     $this->assertEquals(666, $a->getAmount());
 }
開發者ID:edele,項目名稱:travis-tryout,代碼行數:9,代碼來源:MoneyTest.php

示例10: testStringAmount

 /**
  * @covers ::evaluate
  */
 public function testStringAmount()
 {
     $money = new Money();
     $money->setValue(['amount' => '50', 'currency' => 'XTS']);
     $this->assertTrue($money->isValid());
     $obj = $money->evaluate();
     $this->assertInstanceOf('SebastianBergmann\\Money\\Money', $obj);
     $this->assertSame(50, $obj->getAmount());
     $this->assertEquals(new \SebastianBergmann\Money\Currency('XTS'), $obj->getCurrency());
 }
開發者ID:firehed,項目名稱:inputobjects,代碼行數:13,代碼來源:MoneyTest.php

示例11: credit

 public function credit($methodId, $typeId, $marketId, $presenterId, $userId, Money $cost, $entryUser, $referenceId)
 {
     $result = $this->saveCreate(array("ProductCredit" => array("market_id" => $marketId, "user_id" => $userId, "presenter_id" => $presenterId, "product_credit_type_id" => $typeId, "product_credit_entry_type_id" => $methodId, "product_credit_status_type_id" => self::STATUS_SETTLED, "entry_user" => $entryUser, "amount" => (string) $cost->makePositive(), "reference_id" => $referenceId)));
     if ($result) {
         syslog(LOG_DEBUG, "Credit\tLedger {$this->id}\t{$marketId} {$presenterId}\t{$userId}\t{$cost}");
     } else {
         syslog(LOG_DEBUG, "CreditERROR\tLedger\t{$marketId} {$presenterId}\t{$userId}\t{$cost}");
     }
     return $result;
 }
開發者ID:kameshwariv,項目名稱:testexample,代碼行數:10,代碼來源:ProductCredit.php

示例12: 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

示例13: testSetValueAsMoney

 public function testSetValueAsMoney()
 {
     $o = new MoneyFieldTest_Object();
     $f = new MoneyField('MyMoney', 'MyMoney');
     $m = new Money();
     $m->setAmount(123456.78);
     $m->setCurrency('EUR');
     $f->setValue($m);
     $f->saveInto($o);
     $this->assertEquals(123456.78, $o->MyMoney->getAmount());
     $this->assertEquals('EUR', $o->MyMoney->getCurrency());
 }
開發者ID:ivoba,項目名稱:silverstripe-framework,代碼行數:12,代碼來源:MoneyFieldTest.php

示例14: testAddCompositedExtraFields

 public function testAddCompositedExtraFields()
 {
     $obj = new ManyManyListTest_ExtraFields();
     $obj->write();
     $money = new Money();
     $money->setAmount(100);
     $money->setCurrency('USD');
     // the actual test is that this does not generate an error in the sql.
     $obj->Clients()->add($obj, array('Worth' => $money, 'Reference' => 'Foo'));
     $check = $obj->Clients()->First();
     $this->assertEquals('Foo', $check->Reference, 'Basic scalar fields should exist');
     $this->assertInstanceOf('Money', $check->Worth, 'Composite fields should exist on the record');
     $this->assertEquals(100, $check->Worth->getAmount());
 }
開發者ID:aaronleslie,項目名稱:aaronunix,代碼行數:14,代碼來源:ManyManyListTest.php

示例15: display

 /**
  * @param Money|string|int|float $amount
  * @param int $precision
  * @return string
  */
 public function display($amount, $precision = 2)
 {
     $amount = Utils::toStringAmount($amount);
     $money = new Money($amount);
     if ($this->isLeftSign) {
         if ($money->isLessThan('0')) {
             return '-' . $this->sign . $money->abs()->format($precision);
         } else {
             return $this->sign . $money->format($precision);
         }
     } else {
         return $money->format($precision) . $this->sign;
     }
 }
開發者ID:superbalist,項目名稱:php-money,代碼行數:19,代碼來源:Currency.php


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