The nominal exchange rate is the price of one country's currency in terms of another country's currency. It tells you how much of one currency you can get for one unit of another currency. For example, if the nominal exchange rate between the US Dollar (USD) and the Euro (EUR) is 0.90, it means that 1 USD can buy 0.90 EUR, or conversely, 1 EUR can buy approximately 1.11 USD (1 / 0.90).
function calculateNominalExchangeRate() {
var currency1_code = document.getElementById("currency1_code").value.trim().toUpperCase();
var currency1_amount = parseFloat(document.getElementById("currency1_amount").value);
var currency2_code = document.getElementById("currency2_code").value.trim().toUpperCase();
var currency2_amount = parseFloat(document.getElementById("currency2_amount").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
if (isNaN(currency1_amount) || currency1_amount <= 0) {
resultDiv.innerHTML = "Please enter a valid positive amount for Currency 1.";
return;
}
if (isNaN(currency2_amount) || currency2_amount <= 0) {
resultDiv.innerHTML = "Please enter a valid positive amount for Currency 2.";
return;
}
if (currency1_code === "" || currency2_code === "") {
resultDiv.innerHTML = "Please enter valid currency codes.";
return;
}
// Calculate the nominal exchange rate of Currency 1 in terms of Currency 2
// If 1 Currency1 = X Currency2, then the rate is X.
var rate_currency1_in_currency2 = currency2_amount / currency1_amount;
// Calculate the nominal exchange rate of Currency 2 in terms of Currency 1
// If 1 Currency2 = Y Currency1, then the rate is Y.
var rate_currency2_in_currency1 = currency1_amount / currency2_amount;
resultDiv.innerHTML =
"Nominal Exchange Rate (" + currency1_code + "/" + currency2_code + "): " + rate_currency1_in_currency2.toFixed(4) + "" +
"Nominal Exchange Rate (" + currency2_code + "/" + currency1_code + "): " + rate_currency2_in_currency1.toFixed(4);
}