Currency Exchange Rate Calculator
Use this calculator to quickly convert between different currencies based on current exchange rates.
Amount to Convert:
Source Currency:
USD – United States Dollar
EUR – Euro
GBP – British Pound
JPY – Japanese Yen
CAD – Canadian Dollar
AUD – Australian Dollar
CHF – Swiss Franc
CNY – Chinese Yuan
SEK – Swedish Krona
NZD – New Zealand Dollar
Target Currency:
USD – United States Dollar
EUR – Euro
GBP – British Pound
JPY – Japanese Yen
CAD – Canadian Dollar
AUD – Australian Dollar
CHF – Swiss Franc
CNY – Chinese Yuan
SEK – Swedish Krona
NZD – New Zealand Dollar
Convert
// This is a simplified example. In a real-world application, you would fetch
// live exchange rates from an API. For demonstration purposes, we'll use
// fixed, representative rates.
var exchangeRates = {
"USD": {
"EUR": 0.93, "GBP": 0.79, "JPY": 157.43, "CAD": 1.37, "AUD": 1.50, "CHF": 0.89, "CNY": 7.24, "SEK": 10.65, "NZD": 1.64
},
"EUR": {
"USD": 1.08, "GBP": 0.85, "JPY": 169.28, "CAD": 1.47, "AUD": 1.61, "CHF": 0.96, "CNY": 7.78, "SEK": 11.45, "NZD": 1.76
},
"GBP": {
"USD": 1.27, "EUR": 1.18, "JPY": 199.19, "CAD": 1.73, "AUD": 1.89, "CHF": 1.13, "CNY": 9.14, "SEK": 13.47, "NZD": 2.07
},
"JPY": {
"USD": 0.0063, "EUR": 0.0059, "GBP": 0.0050, "CAD": 0.0070, "AUD": 0.0077, "CHF": 0.0046, "CNY": 0.039, "SEK": 0.068, "NZD": 0.10
},
"CAD": {
"USD": 0.73, "EUR": 0.68, "GBP": 0.58, "JPY": 142.73, "AUD": 1.09, "CHF": 0.65, "CNY": 5.28, "SEK": 7.77, "NZD": 1.19
},
"AUD": {
"USD": 0.67, "EUR": 0.62, "GBP": 0.53, "JPY": 130.87, "CAD": 0.92, "CHF": 0.59, "CNY": 4.84, "SEK": 7.12, "NZD": 1.09
},
"CHF": {
"USD": 1.12, "EUR": 1.04, "GBP": 0.88, "JPY": 117.18, "CAD": 1.15, "AUD": 1.17, "CNY": 5.34, "SEK": 8.10, "NZD": 1.25
},
"CNY": {
"USD": 0.14, "EUR": 0.13, "GBP": 0.11, "JPY": 27.61, "CAD": 0.19, "AUD": 0.21, "CHF": 0.19, "SEK": 1.52, "NZD": 0.23
},
"SEK": {
"USD": 0.09, "EUR": 0.08, "GBP": 0.07, "JPY": 14.74, "CAD": 0.13, "AUD": 0.14, "CHF": 0.12, "CNY": 0.66, "NZD": 0.15
},
"NZD": {
"USD": 0.61, "EUR": 0.57, "GBP": 0.48, "JPY": 122.56, "CAD": 0.84, "AUD": 0.92, "CHF": 0.80, "CNY": 4.38, "SEK": 6.55
}
};
// Add self-exchange rates
for (var currency in exchangeRates) {
exchangeRates[currency][currency] = 1.00;
}
function calculateExchangeRate() {
var amountToConvert = parseFloat(document.getElementById("amountToConvert").value);
var sourceCurrency = document.getElementById("sourceCurrency").value;
var targetCurrency = document.getElementById("targetCurrency").value;
var resultDiv = document.getElementById("result");
if (isNaN(amountToConvert) || amountToConvert <= 0) {
resultDiv.innerHTML = "Please enter a valid positive amount to convert.";
return;
}
var rate = exchangeRates[sourceCurrency] ? exchangeRates[sourceCurrency][targetCurrency] : null;
if (rate === null || rate === undefined) {
resultDiv.innerHTML = "Exchange rate not available for the selected currencies.";
return;
}
var convertedAmount = amountToConvert * rate;
resultDiv.innerHTML = "" + amountToConvert.toFixed(2) + " " + sourceCurrency + " is equal to
" + convertedAmount.toFixed(2) + " " + targetCurrency + " ";
}
#exchangeRateCalculator {
font-family: sans-serif;
max-width: 500px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f9f9f9;
}
#exchangeRateCalculator h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
.form-group input[type="number"],
.form-group select {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box; /* Ensures padding doesn't affect width */
}
#exchangeRateCalculator button {
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
#exchangeRateCalculator button:hover {
background-color: #0056b3;
}
#result {
margin-top: 20px;
padding: 15px;
background-color: #e9ecef;
border: 1px solid #ced4da;
border-radius: 4px;
text-align: center;
font-size: 1.1em;
}
#result p {
margin: 0;
}