This calculator helps you quickly convert amounts between different currencies using current or specified exchange rates. Enter the amount you wish to convert, select the source currency, and the target currency to see the converted value.
United States Dollar (USD)
Euro (EUR)
British Pound (GBP)
Japanese Yen (JPY)
Canadian Dollar (CAD)
Australian Dollar (AUD)
United States Dollar (USD)
Euro (EUR)
British Pound (GBP)
Japanese Yen (JPY)
Canadian Dollar (CAD)
Australian Dollar (AUD)
function calculateExchangeRate() {
var amountInput = document.getElementById("amount");
var sourceCurrency = document.getElementById("sourceCurrency").value;
var targetCurrency = document.getElementById("targetCurrency").value;
var resultDiv = document.getElementById("result");
var amount = parseFloat(amountInput.value);
if (isNaN(amount) || amount <= 0) {
resultDiv.innerHTML = "Please enter a valid positive amount.";
return;
}
// In a real-world scenario, you would fetch live exchange rates from an API.
// For this example, we'll use a hardcoded, simplified set of rates.
// These rates are illustrative and not accurate.
var exchangeRates = {
"USD": {
"EUR": 0.93,
"GBP": 0.79,
"JPY": 150.50,
"CAD": 1.36,
"AUD": 1.52
},
"EUR": {
"USD": 1.08,
"GBP": 0.85,
"JPY": 162.00,
"CAD": 1.47,
"AUD": 1.64
},
"GBP": {
"USD": 1.27,
"EUR": 1.18,
"JPY": 191.00,
"CAD": 1.73,
"AUD": 1.94
},
"JPY": {
"USD": 0.0066,
"EUR": 0.0062,
"GBP": 0.0052,
"CAD": 0.0090,
"AUD": 0.010
},
"CAD": {
"USD": 0.73,
"EUR": 0.68,
"GBP": 0.58,
"JPY": 110.00,
"AUD": 1.12
},
"AUD": {
"USD": 0.66,
"EUR": 0.61,
"GBP": 0.51,
"JPY": 98.00,
"CAD": 0.89
}
};
var rate;
if (sourceCurrency === targetCurrency) {
rate = 1;
} else if (exchangeRates[sourceCurrency] && exchangeRates[sourceCurrency][targetCurrency]) {
rate = exchangeRates[sourceCurrency][targetCurrency];
} else {
resultDiv.innerHTML = "Exchange rate not available for this pair.";
return;
}
var convertedAmount = amount * rate;
resultDiv.innerHTML = "" + amount.toFixed(2) + " " + sourceCurrency + " is equal to " + convertedAmount.toFixed(2) + " " + targetCurrency + "";
}
.exchange-rate-calculator {
font-family: sans-serif;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
max-width: 500px;
margin: 20px auto;
background-color: #f9f9f9;
}
.exchange-rate-calculator h2 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
.exchange-rate-calculator p {
line-height: 1.6;
color: #555;
margin-bottom: 25px;
}
.exchange-rate-calculator .input-section {
margin-bottom: 20px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 15px;
align-items: center;
}
.exchange-rate-calculator label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.exchange-rate-calculator input[type="number"],
.exchange-rate-calculator select {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box; /* Ensures padding doesn't affect width */
}
.exchange-rate-calculator button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
.exchange-rate-calculator button:hover {
background-color: #45a049;
}
#result {
margin-top: 20px;
padding: 15px;
border-top: 1px solid #eee;
text-align: center;
font-size: 1.1em;
color: #333;
}
#result p {
margin: 0;
}