calculateCompoundInterest static method

double calculateCompoundInterest(
  1. double principal,
  2. double rate,
  3. double time, {
  4. int compoundingFrequency = 12,
})

Calculate compound interest

principal - Principal amount rate - Interest rate (as decimal, e.g., 0.05 for 5%) time - Time period compoundingFrequency - Compounding frequency per year (default: 12 for monthly) Returns compound interest amount

Implementation

static double calculateCompoundInterest(
  double principal,
  double rate,
  double time,
  {int compoundingFrequency = 12}
) {
  return principal * pow(1 + (rate / compoundingFrequency), compoundingFrequency * time) - principal;
}