当前位置: 首页>>代码示例>>PHP>>正文


PHP Money::getAmount方法代码示例

本文整理汇总了PHP中Money\Money::getAmount方法的典型用法代码示例。如果您正苦于以下问题:PHP Money::getAmount方法的具体用法?PHP Money::getAmount怎么用?PHP Money::getAmount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Money\Money的用法示例。


在下文中一共展示了Money::getAmount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getPrice

 /**
  * @return float|string
  */
 public function getPrice()
 {
     if (null == $this->unitPrice) {
         return 'N\\A';
     }
     return round($this->unitPrice->getAmount() / 100, 2);
 }
开发者ID:cirpo,项目名称:sainsburys-scraper,代码行数:10,代码来源:Product.php

示例2: getAmountInBaseUnits

 public function getAmountInBaseUnits(Money $money)
 {
     $iso = $this->iso4217->getByAlpha3($money->getCurrency()->getName());
     $decimals = $iso['exp'];
     $dividend = pow(10, $decimals);
     return $money->getAmount() / $dividend;
 }
开发者ID:jordicasadevall,项目名称:MoneyFormatter,代码行数:7,代码来源:MoneyFormatter.php

示例3: withdraw

 /**
  * Decrease this account current balance
  *
  * @param Money $amount
  * @throws InsufficientFunds
  *     A member cannot withdraw more than it's account current balance
  */
 public function withdraw(Money $amount)
 {
     if ($amount->greaterThan($this->balance)) {
         throw new InsufficientFunds("Cannot withdraw {$amount->getAmount()}");
     }
     $this->balance = $this->balance->subtract($amount);
 }
开发者ID:zoek1,项目名称:php-testing-tools,代码行数:14,代码来源:Account.php

示例4: convert

 /**
  * @param \Money\Money $money
  * @param        $rounding_mode
  * @return \Money\Money
  * @expectedException InvalidArgumentException
  */
 public function convert(Money $money, RoundingMode $rounding_mode = null)
 {
     if (!$money->getCurrency()->equals($this->baseCurrency)) {
         throw new InvalidArgumentException("The Money has the wrong currency");
     }
     $rounding_mode = $rounding_mode ?: RoundingMode::halfUp();
     return new Money((int) round($money->getAmount() * $this->ratio, 0, $rounding_mode->getRoundingMode()), $this->counterCurrency);
 }
开发者ID:srtfisher,项目名称:money,代码行数:14,代码来源:CurrencyPair.php

示例5: testHydratorHydratesAsExpected

 public function testHydratorHydratesAsExpected()
 {
     $hydrator = new MoneyHydrator();
     $data = ['amount' => 500, 'currency' => 'BRL'];
     $money = new Money(500, new Currency('BRL'));
     $object = $hydrator->hydrate($data, new \stdClass());
     $this->assertEquals($money->getAmount(), $object->getAmount());
     $this->assertEquals($money->getCurrency(), $object->getCurrency());
 }
开发者ID:zfbrasil,项目名称:doctrine-money-module,代码行数:9,代码来源:MoneyHydratorTest.php

示例6: Rate

 function it_converts_money_using_swap(SwapInterface $swap, Money $money, Money $converted, Currency $from, Currency $to)
 {
     $money->getAmount()->willReturn(100);
     $money->getCurrency()->willReturn($from);
     $money->multiply(120.3971)->willReturn($converted);
     $converted->getAmount()->willReturn(12039);
     $converted->getCurrency()->willReturn($to);
     $from->__toString()->willReturn('EUR');
     $to->__toString()->willReturn('RSD');
     $rate = new Rate(120.3971);
     $swap->quote('EUR/RSD')->shouldBeCalled()->willReturn($rate);
     $this->convert($money, $to)->getAmount()->shouldBe(12039);
 }
开发者ID:umpirsky,项目名称:locurro,代码行数:13,代码来源:CurrencySpec.php

示例7: testGetVarCleanVar

 /**
  * @covers Xoops\Core\Kernel\Dtype\DtypeMoney::getVar
  * @covers Xoops\Core\Kernel\Dtype\DtypeMoney::cleanVar
  */
 public function testGetVarCleanVar()
 {
     $testValue = new Money(10000, new Currency('USD'));
     $key = 'money_test';
     $this->xObject[$key] = $testValue;
     $this->xObject[$key] = $this->object->cleanVar($this->xObject, $key);
     $value = $this->xObject->getVar($key, Dtype::FORMAT_NONE);
     $this->assertInstanceOf('\\Money\\Money', $value);
     $this->assertEquals($testValue->getAmount(), $value->getAmount());
     $this->assertEquals($testValue->getCurrency(), $value->getCurrency());
     $this->assertNotSame($value, $testValue);
     $value2 = $this->xObject->getVar($key, Dtype::FORMAT_SHOW);
     $this->assertInstanceOf('\\Money\\Money', $value2);
     $this->assertEquals($testValue->getAmount(), $value2->getAmount());
     $this->assertEquals($testValue->getCurrency(), $value2->getCurrency());
     $this->assertNotSame($value, $value2);
 }
开发者ID:ming-hai,项目名称:XoopsCore,代码行数:21,代码来源:DtypeMoneyTest.php

示例8: format

 /**
  * {@inheritdoc}
  */
 public function format(Money $money)
 {
     $valueBase = (string) $money->getAmount();
     $negative = false;
     if (substr($valueBase, 0, 1) === '-') {
         $negative = true;
         $valueBase = substr($valueBase, 1);
     }
     $fractionDigits = $this->formatter->getAttribute(\NumberFormatter::FRACTION_DIGITS);
     $valueLength = strlen($valueBase);
     if ($valueLength > $fractionDigits) {
         $subunits = substr($valueBase, 0, $valueLength - $fractionDigits) . '.';
         $subunits .= substr($valueBase, $valueLength - $fractionDigits);
     } else {
         $subunits = '0.' . str_pad('', $fractionDigits - $valueLength, '0') . $valueBase;
     }
     if ($negative === true) {
         $subunits = '-' . $subunits;
     }
     return $this->formatter->formatCurrency($subunits, $money->getCurrency()->getCode());
 }
开发者ID:barryvdh,项目名称:money,代码行数:24,代码来源:IntlMoneyFormatter.php

示例9: discount

 /**
  * @param Product $product
  *
  * @return Money
  */
 public function discount(Product $product)
 {
     $discountTotal = $this->money($product);
     // "Global" Basket Discount
     foreach ($product->discounts as $discount) {
         $discountTotal = $discountTotal->add($discount->product($product)->multiply($product->quantity));
     }
     // Coupons
     foreach ($product->coupons as $coupon) {
         // Each discount of an coupon
         foreach ($coupon->discounts() as $productDiscount) {
             // Calculate the amount of discount
             $discount = $productDiscount->product($product);
             $discount = $discount->multiply($product->quantity);
             // Add the discount to the discount total
             $discount = new Money($discount->getAmount(), $product->price->getCurrency());
             $discountTotal = $discountTotal->add($discount);
         }
     }
     return $discountTotal;
 }
开发者ID:draperstudio,项目名称:basket,代码行数:26,代码来源:DefaultReconciler.php

示例10: format

 /**
  * {@inheritdoc}
  */
 public function format(Money $money)
 {
     $valueBase = $money->getAmount();
     $negative = false;
     if ($valueBase[0] === '-') {
         $negative = true;
         $valueBase = substr($valueBase, 1);
     }
     $subunit = $this->currencies->subunitFor($money->getCurrency());
     $valueLength = strlen($valueBase);
     if ($valueLength > $subunit) {
         $formatted = substr($valueBase, 0, $valueLength - $subunit) . '.';
         $formatted .= substr($valueBase, $valueLength - $subunit);
     } else {
         $formatted = '0.' . str_pad('', $subunit - $valueLength, '0') . $valueBase;
     }
     if ($negative === true) {
         $formatted = '-' . $formatted;
     }
     return $formatted;
 }
开发者ID:squigg,项目名称:money,代码行数:24,代码来源:DecimalMoneyFormatter.php

示例11: format

 /**
  * {@inheritdoc}
  */
 public function format(Money $money)
 {
     if (BitcoinCurrencies::CODE !== $money->getCurrency()->getCode()) {
         throw new FormatterException('Bitcoin Formatter can only format Bitcoin currency');
     }
     $valueBase = $money->getAmount();
     $negative = false;
     if ('-' === $valueBase[0]) {
         $negative = true;
         $valueBase = substr($valueBase, 1);
     }
     $subunit = $this->currencies->subunitFor($money->getCurrency());
     $valueBase = Number::roundMoneyValue($valueBase, $this->fractionDigits, $subunit);
     $valueLength = strlen($valueBase);
     if ($valueLength > $subunit) {
         $formatted = substr($valueBase, 0, $valueLength - $subunit);
         if ($subunit) {
             $formatted .= '.';
             $formatted .= substr($valueBase, $valueLength - $subunit);
         }
     } else {
         $formatted = '0.' . str_pad('', $subunit - $valueLength, '0') . $valueBase;
     }
     if ($this->fractionDigits === 0) {
         $formatted = substr($formatted, 0, strpos($formatted, '.'));
     } elseif ($this->fractionDigits > $subunit) {
         $formatted .= str_pad('', $this->fractionDigits - $subunit, '0');
     } elseif ($this->fractionDigits < $subunit) {
         $lastDigit = strpos($formatted, '.') + $this->fractionDigits + 1;
         $formatted = substr($formatted, 0, $lastDigit);
     }
     $formatted = BitcoinCurrencies::SYMBOL . $formatted;
     if (true === $negative) {
         $formatted = '-' . BitcoinCurrencies::SYMBOL . $formatted;
     }
     return $formatted;
 }
开发者ID:squigg,项目名称:money,代码行数:40,代码来源:BitcoinMoneyFormatter.php

示例12: testGetters

 public function testGetters()
 {
     $m = new Money(100, $euro = new Currency('EUR'));
     $this->assertEquals(100, $m->getAmount());
     $this->assertEquals($euro, $m->getCurrency());
 }
开发者ID:hemeragestao,项目名称:money,代码行数:6,代码来源:MoneyTest.php

示例13: applyDeposit

 /**
  * Deposit the given amount to the beneficiary's account
  *
  * @param Money $amount
  * @throws InvalidTransferAmount
  *     A member cannot transfer a negative amount to another member
  */
 protected function applyDeposit(Money $amount)
 {
     if ($amount->isNegative()) {
         throw new InvalidTransferAmount("Cannot transfer negative amount {$amount->getAmount()}");
     }
     $this->account->deposit($amount);
 }
开发者ID:zoek1,项目名称:php-testing-tools,代码行数:14,代码来源:Member.php

示例14: toFloat

 /**
  * @param Money $amount
  *
  * @return float
  */
 public function toFloat(Money $amount)
 {
     return (double) $amount->getAmount() / pow(10, 2);
 }
开发者ID:Codixis,项目名称:CSBill,代码行数:9,代码来源:MoneyFormatter.php

示例15: notGreaterThan

 /**
  * @param Money $money
  * @return bool
  */
 public function notGreaterThan(Money $money)
 {
     return $this->getAmount() <= $money->getAmount();
 }
开发者ID:brightantwiboasiako,项目名称:money,代码行数:8,代码来源:Money.php


注:本文中的Money\Money::getAmount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。