calculateCompoundInterest static method
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;
}