Cpi Inflation Rate Calculator

CPI Inflation Rate Calculator

The Consumer Price Index (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. It is calculated by taking price changes for each item in the predetermined basket of goods and averaging them. Changes in the CPI are used to calculate inflation, which is the rate at which the general level of prices is rising and subsequently, purchasing power is falling. This calculator helps you understand the inflation rate between two periods based on CPI values.

function calculateInflation() { var cpiStart = document.getElementById("cpiStart").value; var cpiEnd = document.getElementById("cpiEnd").value; var resultDiv = document.getElementById("result"); resultDiv.innerHTML = ""; // Clear previous results // Validate inputs if (isNaN(parseFloat(cpiStart)) || isNaN(parseFloat(cpiEnd))) { resultDiv.innerHTML = "Please enter valid numbers for both CPI values."; return; } cpiStart = parseFloat(cpiStart); cpiEnd = parseFloat(cpiEnd); if (cpiStart <= 0) { resultDiv.innerHTML = "CPI at Start Period must be greater than zero."; return; } if (cpiEnd < 0) { resultDiv.innerHTML = "CPI at End Period cannot be negative."; return; } // Calculate inflation rate var inflationRate = ((cpiEnd – cpiStart) / cpiStart) * 100; // Display the result resultDiv.innerHTML = "Inflation Rate: " + inflationRate.toFixed(2) + "%"; } .form-group { margin-bottom: 15px; } .form-group label { display: block; margin-bottom: 5px; font-weight: bold; } .form-group input[type="number"] { padding: 8px; border: 1px solid #ccc; border-radius: 4px; width: 150px; } button { padding: 10px 15px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; } button:hover { background-color: #0056b3; }

Leave a Comment