Calculating Inflation Rate Using Cpi

CPI Inflation Rate Calculator

This calculator helps you determine the inflation rate between two periods using the Consumer Price Index (CPI). Inflation represents the rate at which the general level of prices for goods and services is rising, and subsequently, purchasing power is falling. The CPI is a measure that examines the weighted average of prices of a basket of consumer goods and services, such as transportation, food, and medical care.

.inflation-calculator-container { font-family: sans-serif; border: 1px solid #ccc; padding: 20px; border-radius: 8px; max-width: 500px; margin: 20px auto; background-color: #f9f9f9; } .calculator-title { text-align: center; color: #333; margin-bottom: 15px; } .calculator-description { color: #555; line-height: 1.6; 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[type="number"] { padding: 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 1em; } .input-section input[type="number"]:focus { outline: none; border-color: #007bff; box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25); } button { display: block; width: 100%; padding: 12px 20px; background-color: #007bff; color: white; border: none; border-radius: 4px; font-size: 1.1em; cursor: pointer; transition: background-color 0.3s ease; } button:hover { background-color: #0056b3; } .result-section { margin-top: 25px; padding: 15px; background-color: #e7f3ff; border: 1px solid #cce5ff; border-radius: 4px; text-align: center; font-size: 1.1em; color: #004085; } .result-section strong { color: #002752; } function calculateInflation() { var cpiStartInput = document.getElementById("cpiStart"); var cpiEndInput = document.getElementById("cpiEnd"); var resultDiv = document.getElementById("result"); var cpiStart = parseFloat(cpiStartInput.value); var cpiEnd = parseFloat(cpiEndInput.value); if (isNaN(cpiStart) || isNaN(cpiEnd)) { resultDiv.innerHTML = "Error: Please enter valid numbers for both CPI values."; return; } if (cpiStart <= 0 || cpiEnd <= 0) { resultDiv.innerHTML = "Error: CPI values must be positive numbers."; return; } if (cpiEnd < cpiStart) { resultDiv.innerHTML = "Note: The CPI in the ending period is lower than the starting period, indicating deflation."; } var inflationRate = ((cpiEnd – cpiStart) / cpiStart) * 100; resultDiv.innerHTML = "The inflation rate between the two periods is: " + inflationRate.toFixed(2) + "%"; }

Leave a Comment