convert a money amount (represented by a float or string (based on locale) ie.: R$ 5,00) to cents (represented by an int).

@param float $amount

@throws \UnexpectedValueException

@return int
499235
public static function toCents($amount)
    {
        /*
         * There's probably a better way, but this is what i could come up with
         * to avoid rounding errors
         * todo: search for a better way
         */

        if (!is_float($amount)) {
            $type = gettype($amount);

            throw new \UnexpectedValueException("Needs a float! not $type");
        }

        //handle locales
        $locale = localeconv();

        $amount = str_replace($locale['mon_thousands_sep'], '', $amount);
        $amount = str_replace($locale['mon_decimal_point'], '.', $amount);
        $amount = str_replace($locale['decimal_point'], '.', $amount);

        $parts = explode('.', "$amount");

        // handle the case where $amount has a .0 fraction part
        if (count($parts) == 1) {
            $parts[] = '00';
        }

        list($whole, $fraction) = $parts;

        /*
         * since the documentation only mentions decimals with a precision of two
         * and doesn't specify any rounding method i'm truncating the number
         *
         * the str_pad is to handle the case where $amount is, for example, 6.9
         */
        $fraction = str_pad(substr($fraction, 0, 2), 2, '0');

        $whole = (int) $whole * 100;
        $fraction = (int) $fraction;

        return $whole + $fraction;
    }
855543
public function amount($money)
    {
        if (null === $money) {
            return null;
        }

        $cents = $money * 100;
        if (!is_numeric($money) || $money < 0) {
            throw new \InvalidArgumentException('money amount must be a positive number.');
        }

        return ($this->money_format() == 'cents')
            ? number_format($cents, 0, '', '')
            : number_format($money, 2);
    }
648166
private static function roundTowardsZero($amount)
    {
        $result = self::discardDecimalDigitsZero($amount);

        $point = strpos($result, '.');

        if (false !== $point) {
            $result = substr($result, 0, $point);
        }

        return $result;
    }
1187166
public function toMachine(string $amount, string $swift_code = ''): int
    {
        $swift_code = empty($swift_code) ? config('currency.default_swift_code') : $swift_code;

        return (new DecimalMoneyParser(
                new ISOCurrencies()
            ))->parse(
                preg_replace('/[^0-9.-]/im', '', $amount),
                (new Currency($swift_code))
            )->getAmount();
    }
251024
public function setAmount($amount)
    {
        $amount = (int) (string) $amount;

        if (!Icepay_Parameter_Validation::amount($amount))
            throw new Exception('Amount not valid');
        $this->data->ic_amount = $amount;
        return $this;
    }
1196455
public function exchange(Money $money, $roundingMode = Money::ROUND_HALF_UP)
    {
        if ($money->getCurrency() != $this->getFromCurrency()) {
            throw new Exception\InvalidArgumentException('The Money has the wrong currency');
        }

        return $money->exchange($this->getToCurrency(), $this->getExchangeRate(), $roundingMode);
    }
1055913
private static function _nr3ToDecimal(string $str): float
    {
        /** @var $match string[] */
        if (!preg_match(self::NR3_REGEX, $str, $match)) {
            throw new \UnexpectedValueException(
                "'$str' is not a valid NR3 form real.");
        }
        $m = $match[2];
        // if number started with minus sign
        $inv = $match[1] == "-";
        $e = intval($match[3]);
        // positive exponent
        if ($e > 0) {
            // pad with trailing zeroes
            $num = $m . str_repeat("0", $e);
        } else if ($e < 0) {
            // pad with leading zeroes
            if (strlen($m) < abs($e)) {
                $m = str_repeat("0", abs($e) - strlen($m)) . $m;
            }
            // insert decimal point
            $num = substr($m, 0, $e) . "." . substr($m, $e);
        } else {
            $num = empty($m) ? "0" : $m;
        }
        // if number is negative
        if ($inv) {
            $num = "-$num";
        }
        return floatval($num);
    }
1267505
public static function parse(string $amount)
    {
        $parser = new DecimalMoneyParser(new ISOCurrencies());

        return static::given(
            $parser->parse($amount, new Currency('MYR'))->getAmount()
        );
    }
647594
public static function money($value=0, bool $cents=false, $separator='', bool $no00=false) {
		ref\format::money($value, $cents, $separator, $no00);
		return $value;
	}
1020748
protected function parseAmountFromString($amount)
    {
        if (!is_string($amount)) {
            return $amount;
        }

        $thousandsSeparator = $this->currency->getThousandsSeparator();
        $decimalMark = $this->currency->getDecimalMark();

        $amount = str_replace($this->currency->getSymbol(), '', $amount);
        $amount = preg_replace('/[^0-9\\' . $thousandsSeparator . '\\' . $decimalMark . '\-\+]/', '', $amount);
        $amount = str_replace($this->currency->getThousandsSeparator(), '', $amount);
        $amount = str_replace($this->currency->getDecimalMark(), '.', $amount);

        if (preg_match('/^([\-\+])?\d+$/', $amount)) {
            $amount = (int) $amount;
        } elseif (preg_match('/^([\-\+])?\d+\.\d+$/', $amount)) {
            $amount = (float) $amount;
        }

        return $amount;
    }
368360
public static function formatAmount(int $amount): string
    {
        if (static::$formatCurrencyUsing) {
            return call_user_func(static::$formatCurrencyUsing, $amount);
        }
        $amount = number_format($amount / 100, 2);
        if (StringHelper::startsWith($amount, '-')) {
            return '-' . static::usesCurrencySymbol() . ltrim($amount, '-');
        }

        return static::usesCurrencySymbol() . $amount;
    }
209529
public function formatNumber($amount, array $currency)
    {
        $rounded = $this->round(abs($amount), $currency);
        return number_format($rounded, $currency['decimals'], $currency['decimal_separator'], $currency['thousands_separator']);
    }
62862
protected function transformAmount($amount = '', $currency = '')
    {
        if (!empty($amount) && !empty($currency)) {
            return \Genesis\Utils\Currency::amountToExponent($amount, $currency);
        }

        return false;
    }
358833
public function format($amount, $locale = 'en')
    {
        switch ($locale)
        {
            case 'de':
            case 'tr':
            case 'pt':
            case 'it':
            case 'nl':
                $amount = number_format($amount, 2, ',', '.');
                break;

            case 'fr':
            case 'ru':
                $amount = number_format($amount, 2, ',', ' ');
                break;

            case 'en':
                $amount = number_format($amount, 2, '.', ',');
                break;
        }

        return $amount;
    }
1228256
public function subtract(Money $money)
    {
        if (!$this->currency->equals($money->getCurrency())) {
            throw new CurrencyMismatchException($this.' does not match '.$money);
        }

        $amount = bcsub($this->amount, $money->getAmount(), self::BCSCALE);

        return self::valueOf($amount, $this->currency);
    }
687635
public static function unitPrice($amount, $options = []) {
		$options['decimals'] = \Object\Data\Domains::getSetting('unit_price', 'scale');
		return self::amount($amount, $options);
	}
666485
private static function roundUp($amount)
    {
        $result = self::roundTowardsZero($amount);

        if (1 == bccomp($amount, '0', self::BCSCALE) && 0 != bccomp($amount, $result, self::BCSCALE)) {
            $result = bcadd($result, '1', self::BCSCALE);
        }

        return $result;
    }