PHP code example of vinaikopp / currency-info
1. Go to this page and download the library: Download vinaikopp/currency-info library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vinaikopp / currency-info example snippets
use VinaiKopp\CurrencyInfo\StaticAccess\CurrencyInfo;
$currency = 'EUR';
$locale = 'de_DE';
$formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
$decimalPlaces = CurrencyInfo::getFractionDigitsForCurrency($currency);
$formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $decimalPlaces);
echo $formatter->formatCurrency($value, $currency);
public function __construct(\VinaiKopp\CurrencyInfo\CurrencyInfo $currencyInfo)
{
$this->currencyInfo = $currencyInfo;
$this->currency = 'USD';
$this->locale = 'en_US'
}
public function format($amount)
{
$formatter = new \NumberFormatter($this->locale, \NumberFormatter::CURRENCY);
$decimalPlaces = $this->currencyInfo->getFractionDigitsForCurrency($this->currency);
$formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $decimalPlaces);
return $formatter->formatCurrency($amount, $this->currency);
}