The real exchange rate measures the relative price of goods and services between two countries. It's a crucial indicator for understanding international competitiveness and trade flows. Unlike the nominal exchange rate (the rate at which one currency can be exchanged for another), the real exchange rate accounts for differences in price levels.
function calculateRealExchangeRate() {
var domesticPriceIndex = parseFloat(document.getElementById("domesticPriceIndex").value);
var foreignPriceIndex = document.getElementById("foreignPriceIndex").value);
var nominalExchangeRate = document.getElementById("nominalExchangeRate").value);
var resultDiv = document.getElementById("result");
if (isNaN(domesticPriceIndex) || isNaN(foreignPriceIndex) || isNaN(nominalExchangeRate)) {
resultDiv.innerHTML = "Please enter valid numbers for all fields.";
return;
}
if (foreignPriceIndex === 0) {
resultDiv.innerHTML = "Foreign Price Index cannot be zero.";
return;
}
// Formula: Real Exchange Rate = Nominal Exchange Rate * (Domestic Price Index / Foreign Price Index)
var realExchangeRate = nominalExchangeRate * (domesticPriceIndex / foreignPriceIndex);
resultDiv.innerHTML = "