rateDate for convertCurrency

This commit is contained in:
Divlo 2019-09-16 21:01:02 +02:00
parent ce67cfbe44
commit f78e3a5dfc
3 changed files with 32 additions and 17 deletions

View File

@ -175,34 +175,49 @@ function convertCurrency(value, currency, url) {
switch(currency) {
case '£':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.GBP) * value)).toFixed(2) + ' ' + currency);
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
break;
case '$ Américain':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.USD) * value)).toFixed(2) + ' ' + currency);
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
break;
case '$ Canadien':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.CAD) * value)).toFixed(2) + ' ' + currency);
break;
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.CAD) * value)).toFixed(2) + ' ' + currency);
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
break;
case '$ Australien':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.AUD) * value)).toFixed(2) + ' ' + currency);
break;
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.AUD) * value)).toFixed(2) + ' ' + currency);
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
break;
case '$ Mexicain':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.MXN) * value)).toFixed(2) + ' ' + currency);
break;
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.MXN) * value)).toFixed(2) + ' ' + currency);
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
break;
case 'Fr':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.CHF) * value)).toFixed(2) + ' ' + currency);
break;
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.CHF) * value)).toFixed(2) + ' ' + currency);
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
break;
case '₽':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.RUB) * value)).toFixed(2) + ' ' + currency);
break;
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.RUB) * value)).toFixed(2) + ' ' + currency);
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
break;
case 'R$':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.BRL) * value)).toFixed(2) + ' ' + currency);
break;
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.BRL) * value)).toFixed(2) + ' ' + currency);
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
break;
case '¥':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.JPY) * value)).toFixed(2) + ' ' + currency);
break;
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.JPY) * value)).toFixed(2) + ' ' + currency);
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
break;
case '€':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.EUR) * value)).toFixed(2) + ' ' + currency);
break;
let rateEUR = jsonFixer.rates.EUR;
if (isNaN(rateEUR)) {
$('.results').html(formatNumberResult(value) + ' €');
} else {
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(rateEUR) * value)).toFixed(2) + ' ' + currency);
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
}
break;
default:
$('.results').html(formatNumberResult(value) + ' €');
break;

View File

@ -177,7 +177,6 @@ $(function () {
}
else
{
// let url = 'https://api.exchangeratesapi.io/latest';
let url = 'https://api.exchangeratesapi.io/latest?base=' + currencyOfTheValue;
value = parseFloat(value);
convertCurrency(value, currencyAfter, url);

View File

@ -47,6 +47,7 @@
</div>
<br> <br>
<p class="results text-center"></p>
<p class="rateDate text-center"></p>
</div>
</div>