Accept the amount of money in base unit and returns cents or base unit.

@param int|float $money

@throws \InvalidArgumentException

@return string|null
495682
public function amount($money)
    {
        if (null === $money) {
            return;
        }

        if (is_string($money) || $money < 0) {
            throw new InvalidArgumentException('Money amount must be a positive number.');
        }

        if ($this->getMoneyFormat() === 'cents') {
            return number_format($money, 0, '', '');
        }

        return sprintf('%.2f', number_format($money, 2, '.', '') / 100);
    }
685858
public function getAmount(MoneyInterface $money = null, $currency = null)
    {
        if (null === $money) {
            return 0.0;
        }

        $reduced = $this->bank->reduce($money, $currency);

        return $reduced->getAmount();
    }
508101
public function add(Money $money) : Money
    {
        $this->verifySameCurrency(__METHOD__, $money);

        return new Money($this->amount + $money->amount, $this->currency);
    }
697062
public function divide(
        Money $money,
        $fraction
    ): Money {
        return new Money(
            $money->getAmount() / $fraction,
            $money->getCurrency()
        );
    }
877840
public function convertAndFormat($money, $language = null, $currency = null)
    {
        if (!$currency) {
            $currency = $this->currencyCode;
        }

        $convertedMoney = $money->convertToCurrency($currency);

        return $this->intlFormatter($language)->format($convertedMoney);
    }
1230425
public function multiply(
        Money $money,
        $fraction
    ): Money {
        return new Money(
            $money->getAmount() * $fraction,
            $money->getCurrency()
        );
    }
1303279
public function localizeMoneyFromArrFilter(array $money, string $locale = null): string
    {
        if (isset($money['humanAmount'], $money['baseAmount'])) {
            unset($money['humanAmount']);
        }

        $formattingMoney = new Money($money);

        return $this->localizeMoneyFilter($formattingMoney, $locale);
    }
366441
public static function withSecure($amount, Currency $currency = null)
    {
        if(!is_long($amount))
            throw new InvalidAmountException;
        $money = self::withRaw(0, $currency);
        $money->setFraction($amount / 100);
        $money->setWhole($amount / 100);
        return $money;
    }
462599
public function findPriceByCurrency($currency): ?PriceInterface
    {
        if ($currency instanceof \Money\Currency) {
            $currency = $currency->getCode();
        } elseif ($currency instanceof CurrencyInterface) {
            $currency = $currency->getIsoCodeAlpha();
        }

        if (!is_string($currency)) {
            throw new \InvalidArgumentException('$currency has to be a string');
        }

        foreach ($this->prices as $price) {
            if ($price->getCurrency()->getIsoCodeAlpha() === $currency) {
                return $price;
            }
        }

        return null;
    }
419173
public function exchange(Money $money, $targetCurrency)
    {
        if (is_string($targetCurrency)) {
            $targetCurrency = Currency::create($targetCurrency);
        }

        $exchangeRate = 0;
        return $money->exchange($targetCurrency, $exchangeRate);
    }
654029
private function assertSameCurrency(Money $other)
    {
        if (!$this->isSameCurrency($other)) {
            throw new InvalidArgumentException(
                sprintf(
                    'Cannot add Money with different currency. Have: %s, given: %s.',
                    $this->currency->getIsoCode(),
                    $other->getCurrency()->getIsoCode()
                )
            );
        }
    }
90462
protected function money(int $val): Money
    {
        if (!$this->currency) {
            throw new UnsetCurrencyException('The currency is not set on this stock movement');
        }

        return new Money($val, new Currency($this->currency));
    }
78129
public static function parseByBitcoin($money, $forceCurrency = null, $fractionDigits = 2)
    {
        $parser = new BitcoinMoneyParser($fractionDigits);

        return self::parseByParser($parser, $money, $forceCurrency);
    }
1211451
public function to($unit, $decimals = null, $round = true)
    {
        if (!isset($this->value)) {
            throw new InvalidArgumentException('From value not set');
        }

        if (is_array($unit)) {
            return $this->toMany($unit, $decimals, $round);
        }

        $key = strtolower($unit);

        if (empty($this->units[$key]['base'])) {
            throw new OutOfBoundsException('Unit does not exist');
        }

        if (!isset($this->base_unit)) {
            $this->base_unit = $this->units[$key]['base'];
        }

        if ($this->units[$key]['base'] != $this->base_unit) {
            throw new InvalidArgumentException('Cannot convert between units of different types');
        }

        if (is_callable($this->units[$key]['conversion'])) {
            $result = $this->units[$unit]['conversion']($this->value, true);
        } else {
            $result = $this->value / $this->units[$key]['conversion'];
        }

        if (!isset($decimals)) {
            return $result;
        }

        if ($round) {
            return round($result, $decimals);
        }

        $shifter = $decimals ? pow(10, $decimals) : 1;
        return floor($result * $shifter) / $shifter;
    }
795191
public function subtract(Money $money) : Money
    {
        $this->verifySameCurrency(__METHOD__, $money);

        return $this->add($money->negate());
    }
1267505
public static function parse(string $amount)
    {
        $parser = new DecimalMoneyParser(new ISOCurrencies());

        return static::given(
            $parser->parse($amount, new Currency('MYR'))->getAmount()
        );
    }
986136
public function currency($currency = null) {
        $currency = $currency == null ? $this->currency : $currency;
        return $this->getWord($this->number) . ' ' . $currency;
    }