/**
 * Converts a Money value object to a string for the database reporting etc
 * @param \SebastianBergmann\Money\Money $value
 * @return string
 */
function convertMoneyToString(Money $value)
{
    return convertIntToString($value->getAmount(), $value->getCurrency());
}
Example #2
0
 /**
  * Formats a Money object using PHP's built-in NumberFormatter.
  *
  * @param  \SebastianBergmann\Money\Money $money
  * @return string
  */
 public function format(Money $money)
 {
     return $this->numberFormatter->formatCurrency($money->getAmount() / $money->getCurrency()->getSubUnit(), $money->getCurrency()->getCurrencyCode());
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function getAmount()
 {
     return $this->valueObject->getAmount();
 }
Example #4
0
 /**
  * @return static
  */
 public function setValue(Money $value)
 {
     $this->value = $value->getAmount();
     return $this;
 }
 /**
  * The value "exists" if it is not 0
  * @return bool
  */
 public function exists()
 {
     return $this->value->getAmount() !== 0;
 }
Example #6
0
 /**
  * @param  Money    $money
  * @param  Currency $to
  * @param  int      $roundingMode
  * @return Money
  */
 public function convert(Money $money, Currency $to, $roundingMode = PHP_ROUND_HALF_UP)
 {
     $new = new Money($money->getAmount(), $to);
     $conversionRate = $this->source->getRateBetween($money->getCurrency(), $to);
     return $new->multiply($conversionRate, $roundingMode);
 }