ASB Foreign Exchange Rates Calculator
This calculator helps you estimate the cost of converting one currency to another using ASB foreign exchange rates. Please note that these are indicative rates and the actual rate at the time of transaction may vary.
function getExchangeRate(from, to) {
// This is a mock function. In a real scenario, you'd fetch live rates from an API.
// For demonstration, we'll use a fixed set of rates.
var rates = {
"NZD": { "AUD": 0.90, "USD": 0.60, "EUR": 0.55, "GBP": 0.45, "JPY": 85.0 },
"AUD": { "NZD": 1.11, "USD": 0.67, "EUR": 0.61, "GBP": 0.50, "JPY": 95.0 },
"USD": { "NZD": 1.67, "AUD": 1.50, "EUR": 0.92, "GBP": 0.75, "JPY": 140.0 },
"EUR": { "NZD": 1.81, "AUD": 1.62, "USD": 1.08, "GBP": 0.81, "JPY": 151.0 },
"GBP": { "NZD": 2.22, "AUD": 2.00, "USD": 1.33, "EUR": 1.23, "JPY": 186.0 },
"JPY": { "NZD": 0.0118, "AUD": 0.0105, "USD": 0.0071, "EUR": 0.0066, "GBP": 0.0054 }
};
if (from === to) {
return 1;
}
if (rates[from] && rates[from][to]) {
return rates[from][to];
} else if (rates[to] && rates[to][from]) {
// Inverse rate
return 1 / rates[to][from];
}
return null; // Rate not found
}
function calculateExchange() {
var amount = parseFloat(document.getElementById("amount").value);
var fromCurrency = document.getElementById("fromCurrency").value;
var toCurrency = document.getElementById("toCurrency").value;
var resultDiv = document.getElementById("result");
if (isNaN(amount) || amount <= 0) {
resultDiv.innerHTML = "Please enter a valid amount greater than zero.";
return;
}
var rate = getExchangeRate(fromCurrency, toCurrency);
if (rate === null) {
resultDiv.innerHTML = "Exchange rate not available for the selected currencies.";
return;
}
var convertedAmount = amount * rate;
// Format the output to 2 decimal places for most currencies, but JPY to 0
var formattedAmount;
if (toCurrency === "JPY") {
formattedAmount = convertedAmount.toFixed(0);
} else {
formattedAmount = convertedAmount.toFixed(2);
}
resultDiv.innerHTML = "
Conversion Result
" +
"" + amount + " " + fromCurrency + " is approximately equal to " +
formattedAmount + " " + toCurrency + "" +
"
Indicative exchange rate: 1 " + fromCurrency + " = " + rate.toFixed(4) + " " + toCurrency + "";
}
.exchange-calculator {
font-family: sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.exchange-calculator h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.calculator-inputs {
display: grid;
grid-template-columns: 1fr;
gap: 15px;
}
.input-group {
display: flex;
flex-direction: column;
}
.input-group label {
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
.input-group input[type="number"],
.input-group select {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1em;
}
.exchange-calculator button {
background-color: #007bff;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
font-size: 1.1em;
cursor: pointer;
transition: background-color 0.3s ease;
width: 100%;
}
.exchange-calculator button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
background-color: #e9f5ff;
border: 1px solid #b3d9ff;
border-radius: 4px;
text-align: center;
}
.calculator-result h2 {
margin-bottom: 10px;
color: #0056b3;
}
.calculator-result p {
margin-bottom: 8px;
color: #333;
}
.calculator-result em {
font-size: 0.9em;
color: #666;
}