currency convertor code example
Example 1: float to currency
function floatToEuro(float){
var euroCurrency
euroCurrency = '\u20AC' + float.toLocaleString('nl-NL',{minimumFractionDigits: 2});
console.log(euroCurrency);
return euroCurrency;
};
Example 2: currency converter
currency convertor
Example 3: currency conversion
$from = 'USD';
$to = 'INR';
$cacheKey = 'convertCurrency' . $from . 'To' . $to;
$rate = Cache::remember($cacheKey, 60 * 12, function () use ($from, $to) {
$converterUrl = 'https://free.currencyconverterapi.com/api/v6/convert?q=' . $from . '_' . $to . '&compact=ultra&apiKey=' . env('CURRENCY_CONVERTER_API_KEY');
$data = file_get_contents($converterUrl);
$json = json_decode($data, true);
return implode(" ",$json);
});
$convertedCurrency = $rate * $amount;