This calculator helps you determine the inflation rate between two periods using the GDP Deflator. The GDP deflator is a price index that measures the average level of prices for all new, domestically produced, final goods and services in an economy. It's a broad measure of inflation.
.inflation-calculator {
font-family: sans-serif;
border: 1px solid #ddd;
padding: 20px;
border-radius: 8px;
max-width: 500px;
margin: 20px auto;
background-color: #f9f9f9;
}
.inflation-calculator h2 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
.inflation-calculator p {
line-height: 1.6;
color: #555;
margin-bottom: 25px;
text-align: justify;
}
.input-section {
margin-bottom: 15px;
display: flex;
flex-direction: column;
}
.input-section label {
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.input-section input[type="number"] {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
box-sizing: border-box; /* Ensures padding doesn't affect width */
}
.input-section input[type="number"]:focus {
border-color: #007bff;
outline: none;
box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}
.inflation-calculator button {
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;
margin-top: 10px;
}
.inflation-calculator button:hover {
background-color: #0056b3;
}
.result-section {
margin-top: 25px;
padding: 15px;
background-color: #e9ecef;
border: 1px solid #ced4da;
border-radius: 4px;
text-align: center;
font-size: 1.1em;
color: #333;
}
.result-section strong {
color: #28a745; /* Green for positive inflation */
}
function calculateInflation() {
var currentDeflator = parseFloat(document.getElementById("gdpDeflatorCurrent").value);
var previousDeflator = parseFloat(document.getElementById("gdpDeflatorPrevious").value);
var resultDiv = document.getElementById("result");
if (isNaN(currentDeflator) || isNaN(previousDeflator)) {
resultDiv.innerHTML = "Please enter valid numbers for both GDP deflator values.";
resultDiv.style.color = "#dc3545";
return;
}
if (previousDeflator === 0) {
resultDiv.innerHTML = "Previous period GDP deflator cannot be zero.";
resultDiv.style.color = "#dc3545";
return;
}
// Formula for inflation rate from GDP deflator:
// Inflation Rate = [(Current Period GDP Deflator – Previous Period GDP Deflator) / Previous Period GDP Deflator] * 100
var inflationRate = ((currentDeflator – previousDeflator) / previousDeflator) * 100;
var resultText = "The inflation rate between the two periods is: ";
if (inflationRate > 0) {
resultText += inflationRate.toFixed(2) + "% (Inflation)";
resultDiv.style.color = "#28a745"; // Green for inflation
} else if (inflationRate < 0) {
resultText += Math.abs(inflationRate).toFixed(2) + "% (Deflation)";
resultDiv.style.color = "#dc3545"; // Red for deflation
} else {
resultText += "0.00% (No change)";
resultDiv.style.color = "#6c757d"; // Gray for no change
}
resultDiv.innerHTML = resultText;
}