currency conversion api\ code example
Example 1: rates api
GET https://api.ratesapi.io/api/latest{
"base": "EUR",
"date": "2020-09-11",
"rates": {
"GBP": 0.92408,
"HKD": 9.1871,
"IDR": 17772.61,
"ILS": 4.1004,
"DKK": 7.4402,
"INR": 87.2431,
"CHF": "..."
}
}
Example 2: exchange rates api
$(document).ready(function () {
var baseCurrency = 'USD';
var baseNumber = 1;
var targetCurrency = 'INR';
var targetNumber;
var url;
currencyConverter(baseCurrency, baseNumber,targetCurrency,targetNumber)
$("#base").change(function () {
baseCurrency = $(this).children("option:selected").val();
currencyConverter(baseCurrency,baseNumber,targetCurrency,targetNumber)
});
$("#baseNumber").change(function(){
baseNumber = $(this).val()
currencyConverter(baseCurrency,baseNumber,targetCurrency,targetNumber)
})
$("#target").change(function () {
targetCurrency = $(this).children("option:selected").val();
currencyConverter(baseCurrency,baseNumber,targetCurrency,targetNumber)
});
$("#targetNumber").change(function(){
targetNumber = $(this).val()
currencyConverter2(baseCurrency,baseNumber,targetCurrency,targetNumber)
})
function currencyConverter(baseCurrency, baseNumber,targetCurrency,targetNumber)
{
url = "https://api.exchangeratesapi.io/latest?symbols="+targetCurrency+"&base="+baseCurrency
$.get(url,function(data){
console.log(data.rates)
for (let [key, value] of Object.entries(data.rates)) {
var result = value * baseNumber
$("#targetNumber").val(result)
}
console.log(`data.rates.${targetCurrency}`)
})
}
function currencyConverter2(baseCurrency, baseNumber,targetCurrency,targetNumber)
{
url = "https://api.exchangeratesapi.io/latest?symbols="+baseCurrency+"&base="+targetCurrency
$.get(url,function(data){
console.log(data.rates)
for (let [key, value] of Object.entries(data.rates)) {
console.log(value)
var result = value * targetNumber
$("#baseNumber").val(result)
}
console.log(`data.rates.${targetCurrency}`)
})
}
});Copy