Understanding GDP growth rate is crucial for assessing the economic health and performance of a country or region over time. The Gross Domestic Product (GDP) represents the total monetary value of all the finished goods and services produced within a country's borders in a specific time period. GDP growth rate measures the percentage change in GDP from one period to another, typically quarter-over-quarter or year-over-year. A positive growth rate indicates economic expansion, while a negative growth rate signifies an economic contraction or recession. This calculator helps you quickly determine the GDP growth rate given two consecutive GDP values.
function calculateGdpGrowth() {
var previousGdp = parseFloat(document.getElementById("previousGdp").value);
var currentGdp = parseFloat(document.getElementById("currentGdp").value);
var resultDiv = document.getElementById("result");
if (isNaN(previousGdp) || isNaN(currentGdp)) {
resultDiv.innerHTML = "Please enter valid numbers for both GDP values.";
return;
}
if (previousGdp < 0 || currentGdp < 0) {
resultDiv.innerHTML = "GDP values cannot be negative.";
return;
}
if (previousGdp === 0) {
resultDiv.innerHTML = "The GDP of the previous period cannot be zero for this calculation.";
return;
}
var growthRate = ((currentGdp – previousGdp) / previousGdp) * 100;
resultDiv.innerHTML = "The GDP Growth Rate is: " + growthRate.toFixed(2) + "%";
}
#gdp-growth-calculator {
font-family: sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 500px;
margin: 20px auto;
background-color: #f9f9f9;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.form-group input[type="number"] {
width: calc(100% – 22px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #45a049;
}
#result {
margin-top: 20px;
font-size: 1.1em;
font-weight: bold;
color: #333;
}