本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例12: testGetters
public function testGetters()
{
$m = new Money(100, $euro = new Currency('EUR'));
$this->assertEquals(100, $m->getAmount());
$this->assertEquals($euro, $m->getCurrency());
}
示例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);
}
示例14: toFloat
/**
* @param Money $amount
*
* @return float
*/
public function toFloat(Money $amount)
{
return (double) $amount->getAmount() / pow(10, 2);
}
示例15: notGreaterThan
/**
* @param Money $money
* @return bool
*/
public function notGreaterThan(Money $money)
{
return $this->getAmount() <= $money->getAmount();
}