function calculateCAGR() {
// 1. Get inputs using var and exactly matching IDs
var initialValStr = document.getElementById("initialValue").value;
var finalValStr = document.getElementById("finalValue").value;
var periodsStr = document.getElementById("numPeriods").value;
// 2. Parse inputs to numbers
var initialVal = parseFloat(initialValStr);
var finalVal = parseFloat(finalValStr);
var periods = parseFloat(periodsStr);
var resultDiv = document.getElementById("growthResult");
// 3. Validate inputs
if (isNaN(initialVal) || isNaN(finalVal) || isNaN(periods)) {
resultDiv.style.display = "block";
resultDiv.innerHTML = 'Please enter valid numerical values for all fields.';
return;
}
if (initialVal <= 0 || periods <= 0) {
resultDiv.style.display = "block";
resultDiv.innerHTML = 'Starting Value and Number of Periods must be greater than zero for CAGR calculation.';
return;
}
// 4. The core CAGR Formula: ((Final / Initial)^(1 / Periods)) – 1
// Using Math.pow for the exponentiation
var rawGrowthRatio = finalVal / initialVal;
var exponent = 1 / periods;
var cagrDecimal = Math.pow(rawGrowthRatio, exponent) – 1;
// 5. Convert to percentage
var cagrPercentage = cagrDecimal * 100;
// 6. Calculate total absolute growth percentage for context
var totalGrowthPercentage = ((finalVal – initialVal) / initialVal) * 100;
// 7. Display results
resultDiv.style.display = "block";
resultDiv.innerHTML =
'
Compound Annual Growth Rate (CAGR)
' +
'
' + cagrPercentage.toFixed(2) + '%
' +
'
Total growth of ' + totalGrowthPercentage.toFixed(2) + '% over ' + periods + ' periods.
';
}
Understanding Growth Rate and CAGR
Calculating growth rate is essential for evaluating the success of a business, an investment, or any metric that changes over time. While a simple percentage growth calculation tells you the total change, it doesn't account for the time it took to achieve that growth.
This calculator uses the Compound Annual Growth Rate (CAGR) formula. CAGR is preferred by investors and business analysts because it provides a smoothed annual average rate of growth, eliminating the volatility that might occur year-to-year. It answers the question: "If this metric grew at a steady rate every year to get from the starting value to the ending value, what would that rate be?"
The CAGR Formula Used
The mathematics behind this calculator is based on the standard CAGR formula:
CAGR = ( (Ending Value / Starting Value)^(1 / Number of Periods) ) – 1
Realistic Example
Imagine a startup company looking to measure its revenue growth over the past few years to present to investors.
Starting Value: In Year 1, their revenue was 100,000.
Ending Value: By the end of Year 5, their revenue grew to 250,000.
Number of Periods: The time elapsed is 4 years (from the end of Year 1 to end of Year 5).
Entering these figures into the calculator (Starting: 100000, Ending: 250000, Periods: 4) reveals a CAGR of approximately 25.74%. Even though the actual growth year-to-year might have been bumpy (e.g., +10%, +40%, +5%, +50%), the CAGR represents the equivalent steady compounded growth rate.