Compound interest

The WebAssembly module exports a compound interest function that takes a principal, an annual rate expressed as a percentage, a number of years, and a number of compounding periods per year, and returns the final balance. It applies the standard compound interest formula, with the rate divided by 100 to convert the percentage into a fraction. Like the percentage function it is a free function with no keypad button, available to any JavaScript that imports the module.

The four arguments

The function returns the final balance, not the interest earned. Subtract the principal from the result to get the interest on its own.

Worked examples

These figures are the ones the crate's unit tests assert, so they describe what the function actually returns rather than what the formula ought to give.

Why there is no compound interest key

The function needs four arguments and the keypad is a single-line display with one working value and one memory register, so there is nowhere to enter them. It is exported and imported but never called by the page. Reaching it requires importing the module yourself, as described on the operations page.

Questions and answers

How do I enter compound interest on the calculator keypad?

You cannot. The function takes four arguments and the keypad has one display and one memory register, so it has no button. The function is exported by the WebAssembly module for direct use from JavaScript.

Should the rate be entered as 5 or as 0.05?

As 5. The function expects the annual rate as a percentage and divides it by 100 internally.

Does the function return the interest earned or the final balance?

The final balance. Subtract the principal from the result to get the interest on its own.