Calculate Conversion Rate Currency

Currency Conversion Calculator

This calculator helps you convert amounts between different currencies using a real-time exchange rate. Simply enter the amount you wish to convert and select the source and target currencies.

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
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
function calculateConversion() { var amount = parseFloat(document.getElementById("amountToConvert").value); var sourceCurrency = document.getElementById("sourceCurrency").value; var targetCurrency = document.getElementById("targetCurrency").value; var resultDiv = document.getElementById("result"); if (isNaN(amount) || amount <= 0) { resultDiv.innerHTML = "Please enter a valid positive amount to convert."; return; } // This is a simplified example using fixed rates for demonstration. // In a real-world application, you would fetch real-time exchange rates from an API. var exchangeRates = { "USD": {"EUR": 0.93, "GBP": 0.79, "JPY": 157.10, "CAD": 1.37, "AUD": 1.50, "CHF": 0.89, "CNY": 7.25, "SEK": 10.45, "NZD": 1.65}, "EUR": {"USD": 1.08, "GBP": 0.85, "JPY": 169.20, "CAD": 1.48, "AUD": 1.62, "CHF": 0.96, "CNY": 7.81, "SEK": 11.27, "NZD": 1.78}, "GBP": {"USD": 1.26, "EUR": 1.18, "JPY": 199.30, "CAD": 1.74, "AUD": 1.91, "CHF": 1.13, "CNY": 9.21, "SEK": 13.31, "NZD": 2.10}, "JPY": {"USD": 0.0064, "EUR": 0.0059, "GBP": 0.0050, "CAD": 0.0087, "AUD": 0.0096, "CHF": 0.0057, "CNY": 0.046, "SEK": 0.067, "NZD": 0.11}, "CAD": {"USD": 0.73, "EUR": 0.68, "GBP": 0.57, "JPY": 114.90, "AUD": 1.10, "CHF": 0.65, "CNY": 5.30, "SEK": 7.65, "NZD": 1.21}, "AUD": {"USD": 0.67, "EUR": 0.62, "GBP": 0.52, "JPY": 104.60, "CAD": 0.91, "CHF": 0.59, "CNY": 4.83, "SEK": 6.97, "NZD": 1.09}, "CHF": {"USD": 1.12, "EUR": 1.04, "GBP": 0.88, "JPY": 112.00, "CAD": 1.54, "AUD": 1.69, "CNY": 6.27, "SEK": 9.10, "NZD": 1.44}, "CNY": {"USD": 0.14, "EUR": 0.13, "GBP": 0.11, "JPY": 21.70, "CAD": 0.19, "AUD": 0.21, "CHF": 0.16, "SEK": 1.45, "NZD": 0.23}, "SEK": {"USD": 0.096, "EUR": 0.089, "GBP": 0.075, "JPY": 15.00, "CAD": 0.13, "AUD": 0.14, "CHF": 0.11, "CNY": 0.69, "NZD": 0.16}, "NZD": {"USD": 0.61, "EUR": 0.56, "GBP": 0.48, "JPY": 121.50, "CAD": 1.33, "AUD": 1.46, "CHF": 0.87, "CNY": 4.35, "SEK": 6.27} }; var rate = 0; if (sourceCurrency === targetCurrency) { rate = 1; } else if (exchangeRates[sourceCurrency] && exchangeRates[sourceCurrency][targetCurrency]) { rate = exchangeRates[sourceCurrency][targetCurrency]; } else { resultDiv.innerHTML = "Conversion rate not available for the selected currencies. Please try again later."; return; } var convertedAmount = amount * rate; resultDiv.innerHTML = amount + " " + sourceCurrency + " is equal to " + convertedAmount.toFixed(2) + " " + targetCurrency; } #currency-converter { font-family: sans-serif; max-width: 500px; margin: 20px auto; padding: 20px; border: 1px solid #ddd; border-radius: 8px; background-color: #f9f9f9; } #currency-converter h2 { text-align: center; color: #333; margin-bottom: 15px; } .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: calc(100% – 10px); padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; } #currency-converter button { display: block; width: 100%; padding: 12px; background-color: #007bff; color: white; border: none; border-radius: 4px; font-size: 18px; cursor: pointer; transition: background-color 0.3s ease; } #currency-converter button:hover { background-color: #0056b3; } #result { margin-top: 20px; padding: 15px; border: 1px solid #e0e0e0; border-radius: 4px; background-color: #fff; font-size: 18px; text-align: center; color: #333; }

Leave a Comment