jimmerioles/bitcoin-currency-converter-php

View on GitHub
src/Util/currency_formatter_helper.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

use Jimmerioles\BitcoinCurrencyConverter\Exception\InvalidArgumentException;

if (! function_exists('format_to_currency')) {
    /**
     * Format to currency type.
     *
     * @param  string $currencyCode
     * @param  float  $value
     * @return float
     */
    function format_to_currency($currencyCode, $value)
    {
        if (is_crypto_currency($currencyCode)) {
            return round($value, 8, PHP_ROUND_HALF_UP);
        }

        if (is_fiat_currency($currencyCode)) {
            return round($value, 2, PHP_ROUND_HALF_UP);
        }

        throw new InvalidArgumentException("Argument \$currencyCode not valid currency code, '{$currencyCode}' given.");
    }
}