Understanding inflation is crucial for managing your personal finances and making informed investment decisions. Inflation represents the rate at which the general level of prices for goods and services is rising, and subsequently, purchasing power is falling. This calculator helps you determine the inflation rate between two specific years.
Inflation Rate:
.calculator-wrapper {
font-family: sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 500px;
margin: 20px auto;
background-color: #f9f9f9;
}
.calculator-wrapper h2, .calculator-wrapper h3 {
text-align: center;
color: #333;
}
.input-section {
margin-top: 15px;
display: flex;
flex-direction: column;
gap: 10px;
}
.input-section label {
font-weight: bold;
color: #555;
}
.input-section input[type="number"] {
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
}
.calculator-wrapper button {
display: block;
width: 100%;
padding: 12px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 1.1rem;
cursor: pointer;
margin-top: 20px;
transition: background-color 0.3s ease;
}
.calculator-wrapper button:hover {
background-color: #0056b3;
}
.result-section {
margin-top: 25px;
text-align: center;
padding-top: 15px;
border-top: 1px solid #eee;
}
#result {
font-size: 1.5rem;
font-weight: bold;
color: #28a745;
margin-top: 10px;
}
function calculateInflation() {
var priceYear1Input = document.getElementById("priceYear1");
var priceYear2Input = document.getElementById("priceYear2");
var resultDiv = document.getElementById("result");
var priceYear1 = parseFloat(priceYear1Input.value);
var priceYear2 = parseFloat(priceYear2Input.value);
if (isNaN(priceYear1) || isNaN(priceYear2)) {
resultDiv.innerHTML = "Please enter valid numbers for both prices.";
return;
}
if (priceYear1 <= 0) {
resultDiv.innerHTML = "Price in Year 1 must be greater than zero.";
return;
}
// Inflation Rate Formula: ((Price in Year 2 – Price in Year 1) / Price in Year 1) * 100
var inflationRate = ((priceYear2 – priceYear1) / priceYear1) * 100;
// Handle negative inflation (deflation)
if (inflationRate < 0) {
resultDiv.innerHTML = inflationRate.toFixed(2) + "% (Deflation)";
} else {
resultDiv.innerHTML = inflationRate.toFixed(2) + "%";
}
}