## JavaScript - Inflation/Escalation with Total over X years

inflation calculator
cpi formula
formula to calculate inflation
how to calculate cpi
how to calculate inflation rate
cpi calculator
how to calculate cpi in excel
how to calculate deflation rate

I've been building a JS calculator to help with annual fees, but I'm struggling with one part.

There's a field that should show the total of a yearly fee which increases by X% per-year over Y years.

A bit hard to explain, so below is an example:

Person A has a salary of £24,000 which increases every year by 3.5%. We need to figure out the total Person A has been paid over 7.373 years.

If I did this in a FOR loop, it works fine if the years are just integers, however I need a solution for floats and I'm not sure how to approach this - we need to figure out the total over 7.373 years and not just 7 (just an example, it could be any number of years).

Here's the test code that works fine using integers:

```year = 7;
money = 24000;
num = 0;
percent = 1 + (3.5 / 100);
for(y = 1; y <= year; y++) {
num = num + 1;
money = money * interest
console.log('Year '+ num + ' - ' + money);
// other stuff
}
```

The resulting output would look like:

Year 1 - 24,840.00 Year 2 - 25,709.40 Year 3 - 26,609.23 Year 4 - 27,540.55 Year 5 - 28,504.47 Year 6 - 29,502.13 Year 7 - 30,534.70

What I actually need is the total sum of all of those years (ie. 193,240.48), and not just to calculate against 7 years, but 7.373 years (or whatever defined float is entered).

You need to calculate one more year. In this example you need year 8. Then you can take the percentage of the year and add it to the sum.

In your loop you can use `Math.ceil(year)`. This will round the year up, so with years of `7.373` you will get 8 loops. You can test for this last year and adjust the percentage accordingly:

```let year = 7.373;
let money = 24000;
let num = 0;
let total = 0
let percent = 1 + (3.5 / 100);
for (let y = 1; y <= Math.ceil(year); y++) {
num = num + 1;
money = money * percent
if (y > year) { // year 8
// the sum will only increas .373 of year 8
money *= 1 - (y - year)
console.log(`Calculating \${1- (y-year)} of year \${y}`)
}

//  increment total
total += money

console.log('Year ' + num + ' - ' + money.toLocaleString('en-GB', {
style: 'currency',
currency: 'GBP'
}));
// other stuff
}
console.log(`Total: after \${year} years:`, total.toLocaleString('en-GB', {
style: 'currency',
currency: 'GBP'
}))```

[PDF] Calculating Inflation Factors for Cost Estimates, Even a modest rate of inflation can seriously erode purchasing power over time. Assume \$870,000 in five years to match the purchasing power of \$750,000 today. At the end Calculating Total Cost & Inflation Factor for Estimates. Inflation is  The first payment, which was at year 1, is going to be multiplied by the factor F over P, 12% of escalation rate, and 1 year of compounding. And the same for the other payments. So the \$15,000 of income in the year 2 is going to be compounded for 2 years and 12% of escalation rate, and last year, year 3, it has to be compounded for 3 years by

I recommend creating an array of those values and then summing up to 7 years, and then adding the 8th year as a .373 fraction of that year.

```const year = 8;
let money = 24000;
const percent = 1 + (3.5 / 100);
let arrayOfYears = []

for(y = 1; y <= year; y++) {
money = money * interest
arrayOfYears.push(money)
console.log('Year '+ y + ' - ' + money);
// other stuff
}

let sum = arrayOfYears.reduce((acc, cur, idx) => {
if (idx < 7) {
return acc + cur
} else {
return acc + (cur * 0.373)
}
}, 0)

console.log(sum)
```

The Solid Waste Handbook: A Practical Guide, Table 4.7 Pro Forma Analysis, Landfill Alternative (Dollars per Year x 1000) "At 640 ac (2.6 million "Inflation rate: 5%/year. 'Total costs minus all revenues. approximately the same market value in 1983 as in 1973 according to a current prices and assume no escalation (or only a few percent per year) for these materials. assuming that inflation and escalation rates are the same each year. The increase in constant year dollar costs relative to the base year (here, year 1) is real price change (RPC). The gap between RPC and the remaining escalation is inflation plus an interaction term, interpreted as inflation on RPC.

The specification of your problem leaves some interpretation so different possibilities. Usually increases after 1 year, i.e at the end of the full year there's an increment. Also as you are applying the whole percentage to a year the fractional year can be a fraction of the salary at end of year 7. The other way interest is calculated could be daily but that's not what your example showed. See this example below. Note the discussion above about rounding etc with floats to decimals and introduction of errors. In the code below it maybe necessary to fix to 2 decimal places at various stages to ensure accuracy but you hopefully get the idea.

```        //Could round or make to fixed number of decimal places
//the calculation maybe better to 2 decimal places i.e sprinkle with parseFloat(n.toFixed(2))
function toDecStr(n) {
return n.toLocaleString('en-GB',{minimumFractionDigits:2, maximumFractionDigits:2});
}

let targetYears = 7.373
let startingSalary = 24000.00;
let annualIncrease = 0.035; //3.5% increase, presumably at the end of each year
let wholeYears = Math.trunc(targetYears);
let fractionOfYear = targetYears - wholeYears; //Could round to a number of decimal places
console.log("Whole years:%s + fraction of a year: %s",wholeYears,fractionOfYear);
//calulate the whole number of years
let totalSalary = startingSalary;
let previousSalary = startingSalary
console.log('Salary earned in year n and total salary to date:');
console.log('Year %s = %s',1,toDecStr(startingSalary), toDecStr(totalSalary));
for(let i = 2; i <= wholeYears; i++) {
let newSalary = previousSalary * (1.0 + annualIncrease);
totalSalary += newSalary; //At end of year i
console.log('Year %s = %s %s', i, toDecStr(newSalary), toDecStr(totalSalary));
previousSalary = newSalary;
}
// + Fractional year
let earningsInPartialYear = previousSalary * fractionOfYear;
totalSalary += earningsInPartialYear;
console.log('Year %s %s', targetYears, toDecStr(earningsInPartialYear), toDecStr(totalSalary));
//Note no salary increase in a fractional year (until the end the year)
```

Gives:

```Whole years:7 + fraction of a year: 0.3730000000000002
Salary earned in year n and total salary to date:
Year 1 = 24,000.00 24,000.00
Year 2 = 24,840.00 48,840.00
Year 3 = 25,709.40 74,549.40
Year 4 = 26,609.23 101,158.63
Year 5 = 27,540.55 128,699.18
Year 6 = 28,504.47 157,203.65
Year 7 = 29,502.13 186,705.78
Year 7.373 11,004.29 197,710.07
```

CPI Calculator to Calculate Future or Historical Inflation, See the effects inflation has had on a past sum of money based on the US Price Index (CPI) Calculator to Calculate the Effects of Inflation Over Time. As others have said you're subtracting from the numeric values returned from methods like date.getDate(), you need to reset those values on your date variable.I've created a method below that will do this for you.

Example question calculating CPI and inflation (video), Learn how and why we adjust GDP numbers for inflation. To convert nominal economic data from several different years into real, inflation-adjusted data, the to a rise in the overall level of prices or to a rise in quantities of goods produced. However, over time, the rise in nominal GDP looks much larger than the rise in​  Firstly, anything you do to the DOM could be a user visible change. If you change the DOM, the browser has to lay everything out again. It could be faster, if the browser caches the changes, then only lays out every X ms (assuming it doesn't do this already), but perhaps there's not a huge demand for this kind of feature.

Adjusting nominal values to real values (article), Each price index has a base year of 1990 and increases over time. The price index for Next compute the total cost of the market basket in Year 1: \$60 + \$10 +  Year dollars or convert to dollars using an inflation indexConstant Year. Escalation indexes are, however, useful for normalizing historical data. • Document and label all indexes used in an analysis. B. Scope . This Handbook focuses on the difference between inflation and escalation and s what they mean for cost analysis.

Calculating Inflation with Index Numbers, United States inflation slowed greatly in March as consumer prices, with the help of the coronavirus, recorded their largest decline for a month in over five years, a​  Our inflation calculator helps you understand how the purchasing power of a certain dollar amount will change over time. In general, the value of money decreases over time. This means that \$5 today won’t buy you the same amount of goods or services as it would in 10 years.

• If nothing else, just a simple math can get you there (although I don't think this is the best possible approach for this kind of problem). If you know that for 7 years the result is `30,534.70`, you can calculate the amount for 7.373 as `(7.337*30,534.70) / 7`.