This calculator helps you determine the equivalent value of one currency in another, specifically when you're looking to convert from a target currency back to your base currency. This is often useful when dealing with international transactions, travel, or investments.
.exchange-rate-calculator {
font-family: sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 400px;
margin: 20px auto;
background-color: #f9f9f9;
}
.exchange-rate-calculator h2 {
text-align: center;
margin-bottom: 15px;
color: #333;
}
.exchange-rate-calculator p {
text-align: justify;
margin-bottom: 20px;
color: #555;
line-height: 1.5;
}
.input-section {
display: flex;
flex-direction: column;
gap: 10px;
margin-bottom: 15px;
}
.input-section label {
font-weight: bold;
color: #444;
}
.input-section input {
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
}
.exchange-rate-calculator button {
width: 100%;
padding: 12px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 1.1rem;
cursor: pointer;
transition: background-color 0.3s ease;
}
.exchange-rate-calculator button:hover {
background-color: #0056b3;
}
#result {
margin-top: 20px;
font-size: 1.2rem;
font-weight: bold;
color: #28a745;
text-align: center;
}
function calculateReverseExchangeRate() {
var amountToConvert = parseFloat(document.getElementById("amountToConvert").value);
var currentRate = parseFloat(document.getElementById("currentRate").value);
var resultElement = document.getElementById("result");
if (isNaN(amountToConvert) || isNaN(currentRate) || currentRate === 0) {
resultElement.textContent = "Please enter valid numbers for amount and rate. Rate cannot be zero.";
resultElement.style.color = "red";
return;
}
// The reverse exchange rate is 1 / currentRate
// To convert 'amountToConvert' (in Target Currency) back to Base Currency:
// Amount in Base = Amount in Target / (Rate of Base to Target)
var amountInBaseCurrency = amountToConvert / currentRate;
resultElement.textContent = "Equivalent in Base Currency: " + amountInBaseCurrency.toFixed(2);
resultElement.style.color = "#28a745";
}