US Dollar Exchange Rate Calculator
This calculator helps you convert amounts between US Dollars (USD) and other major currencies based on a provided exchange rate. Simply enter the amount you wish to convert and the current exchange rate.
Amount to Convert:
Exchange Rate (1 USD = X Foreign Currency):
Convert From:
USD to Foreign Currency
Foreign Currency to USD
Calculate
.calculator-container {
font-family: Arial, sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 400px;
margin: 20px auto;
background-color: #f9f9f9;
}
.calculator-title {
text-align: center;
color: #333;
margin-bottom: 15px;
}
.calculator-description {
text-align: center;
color: #555;
font-size: 0.9em;
margin-bottom: 20px;
}
.input-section label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.input-section input[type="number"],
.input-section select {
width: calc(100% – 12px);
padding: 8px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
button {
display: block;
width: 100%;
padding: 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 1em;
margin-top: 10px;
}
button:hover {
background-color: #0056b3;
}
#result {
margin-top: 20px;
font-size: 1.1em;
font-weight: bold;
text-align: center;
color: #007bff;
padding: 10px;
background-color: #e7f3ff;
border: 1px solid #cce5ff;
border-radius: 4px;
}
function calculateExchange() {
var amountToConvert = parseFloat(document.getElementById("amountToConvert").value);
var exchangeRate = parseFloat(document.getElementById("exchangeRate").value);
var conversionType = document.getElementById("conversionType").value;
var resultDiv = document.getElementById("result");
var calculatedAmount = 0;
var fromCurrency = "";
var toCurrency = "";
if (isNaN(amountToConvert) || isNaN(exchangeRate) || amountToConvert < 0 || exchangeRate <= 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for amount and exchange rate.";
return;
}
if (conversionType === "toForeign") {
calculatedAmount = amountToConvert * exchangeRate;
fromCurrency = "USD";
toCurrency = "Foreign Currency";
resultDiv.innerHTML = amountToConvert.toFixed(2) + " " + fromCurrency + " is equal to " + calculatedAmount.toFixed(2) + " " + toCurrency;
} else { // toUSD
calculatedAmount = amountToConvert / exchangeRate;
fromCurrency = "Foreign Currency";
toCurrency = "USD";
resultDiv.innerHTML = amountToConvert.toFixed(2) + " " + fromCurrency + " is equal to " + calculatedAmount.toFixed(2) + " " + toCurrency;
}
}