/** * 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()); }
/** * 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()); }
/** * {@inheritdoc} */ public function getAmount() { return $this->valueObject->getAmount(); }
/** * @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; }
/** * @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); }