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) { switch(currency) {
case '£': case '£':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.GBP) * value)).toFixed(2) + ' ' + currency); $('.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; break;
case '$ Américain': case '$ Américain':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.USD) * value)).toFixed(2) + ' ' + currency); $('.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; break;
case '$ Canadien': case '$ Canadien':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.CAD) * value)).toFixed(2) + ' ' + currency); $('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.CAD) * value)).toFixed(2) + ' ' + currency);
break; $('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
break;
case '$ Australien': case '$ Australien':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.AUD) * value)).toFixed(2) + ' ' + currency); $('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.AUD) * value)).toFixed(2) + ' ' + currency);
break; $('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
break;
case '$ Mexicain': case '$ Mexicain':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.MXN) * value)).toFixed(2) + ' ' + currency); $('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.MXN) * value)).toFixed(2) + ' ' + currency);
break; $('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
break;
case 'Fr': case 'Fr':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.CHF) * value)).toFixed(2) + ' ' + currency); $('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.CHF) * value)).toFixed(2) + ' ' + currency);
break; $('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
break;
case '₽': case '₽':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.RUB) * value)).toFixed(2) + ' ' + currency); $('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.RUB) * value)).toFixed(2) + ' ' + currency);
break; $('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
break;
case 'R$': case 'R$':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.BRL) * value)).toFixed(2) + ' ' + currency); $('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.BRL) * value)).toFixed(2) + ' ' + currency);
break; $('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
break;
case '¥': case '¥':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.JPY) * value)).toFixed(2) + ' ' + currency); $('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.JPY) * value)).toFixed(2) + ' ' + currency);
break; $('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
break;
case '€': case '€':
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.EUR) * value)).toFixed(2) + ' ' + currency); let rateEUR = jsonFixer.rates.EUR;
break; 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: default:
$('.results').html(formatNumberResult(value) + ' €'); $('.results').html(formatNumberResult(value) + ' €');
break; break;

View File

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

View File

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