This calculator helps you estimate the inflation rate in India based on the Consumer Price Index (CPI) for two different periods. Inflation measures the rate at which the general level of prices for goods and services is rising, and subsequently, purchasing power is falling.
.inflation-calculator-container {
font-family: sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 400px;
margin: 20px auto;
background-color: #f9f9f9;
}
.inflation-calculator-container h2 {
text-align: center;
color: #333;
margin-bottom: 15px;
}
.inflation-calculator-container p {
color: #555;
line-height: 1.6;
margin-bottom: 20px;
font-size: 0.95em;
}
.input-section {
margin-bottom: 15px;
display: grid;
grid-template-columns: 1fr;
gap: 10px;
}
.input-section label {
display: block;
margin-bottom: 5px;
color: #444;
font-weight: bold;
}
.input-section input[type="number"] {
width: calc(100% – 12px);
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box; /* Include padding and border in the element's total width and height */
}
.inflation-calculator-container button {
display: block;
width: 100%;
padding: 10px 15px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 1em;
margin-top: 10px;
}
.inflation-calculator-container button:hover {
background-color: #0056b3;
}
.result-section {
margin-top: 20px;
padding: 15px;
background-color: #e9ecef;
border: 1px solid #ced4da;
border-radius: 4px;
text-align: center;
font-size: 1.1em;
color: #333;
min-height: 30px; /* Ensure it's visible even when empty */
}
function calculateInflation() {
var cpiYear1Input = document.getElementById("cpiYear1");
var cpiYear2Input = document.getElementById("cpiYear2");
var resultDiv = document.getElementById("result");
var cpiYear1 = parseFloat(cpiYear1Input.value);
var cpiYear2 = parseFloat(cpiYear2Input.value);
if (isNaN(cpiYear1) || isNaN(cpiYear2)) {
resultDiv.innerHTML = "Please enter valid numbers for CPI.";
return;
}
if (cpiYear1 <= 0 || cpiYear2 <= 0) {
resultDiv.innerHTML = "CPI values must be positive.";
return;
}
if (cpiYear2 < cpiYear1) {
resultDiv.innerHTML = "CPI in the later year cannot be less than the earlier year for a positive inflation rate calculation.";
return;
}
var inflationRate = ((cpiYear2 – cpiYear1) / cpiYear1) * 100;
resultDiv.innerHTML = "The estimated inflation rate is: " + inflationRate.toFixed(2) + "%";
}