Growth Rate Calculator Gdp

GDP Growth Rate Calculator

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 = "

Result

GDP Growth Rate: " + growthRate.toFixed(2) + "%"; } .growth-rate-calculator { font-family: Arial, sans-serif; border: 1px solid #ccc; padding: 20px; border-radius: 8px; max-width: 500px; margin: 20px auto; background-color: #f9f9f9; } .growth-rate-calculator h2 { text-align: center; margin-bottom: 20px; color: #333; } .growth-rate-calculator p { line-height: 1.6; color: #555; margin-bottom: 20px; } .input-section { display: flex; flex-direction: column; gap: 15px; margin-bottom: 20px; } .input-section label { font-weight: bold; color: #444; } .input-section input { padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; width: 100%; box-sizing: border-box; /* Include padding and border in the element's total width and height */ } .growth-rate-calculator button { display: block; width: 100%; padding: 12px 20px; background-color: #007bff; color: white; border: none; border-radius: 4px; font-size: 18px; cursor: pointer; transition: background-color 0.3s ease; } .growth-rate-calculator button:hover { background-color: #0056b3; } .result-section { margin-top: 25px; padding: 15px; border: 1px solid #d4edda; background-color: #d4edda; color: #155724; border-radius: 4px; text-align: center; } .result-section h2 { margin-top: 0; color: #155724; } .result-section strong { font-size: 1.2em; }

Leave a Comment