当前位置: 首页>>代码示例>>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;未经允许,请勿转载。