This calculator helps you determine the percentage change in a country's Gross Domestic Product (GDP) over a specific period. Understanding GDP growth is crucial for assessing economic performance and trends.
function calculateGdpGrowth() {
var gdpCurrent = document.getElementById("gdpCurrent").value;
var gdpPrevious = document.getElementById("gdpPrevious").value;
var resultDiv = document.getElementById("result");
// Input validation
if (isNaN(gdpCurrent) || isNaN(gdpPrevious) || gdpCurrent === "" || gdpPrevious === "") {
resultDiv.innerHTML = "Please enter valid numbers for both GDP values.";
return;
}
if (parseFloat(gdpPrevious) === 0) {
resultDiv.innerHTML = "The GDP of the previous period cannot be zero for growth rate calculation.";
return;
}
var gdpCurrentFloat = parseFloat(gdpCurrent);
var gdpPreviousFloat = parseFloat(gdpPrevious);
// Calculate GDP growth rate
var growthRate = ((gdpCurrentFloat – gdpPreviousFloat) / gdpPreviousFloat) * 100;
resultDiv.innerHTML = "