Problems › JavaScript › finance
Simple interest earned
A saver is told the interest they would earn: principal held for years at a whole-percent annual rate, with no compounding.
- Pay the simple rate: principal × rate × years, in minor units.
- The product is divided by 100 for the percent, rounding down.
- A zero rate, zero principal, or zero years all pay nothing.
simpleInterest(principal: int, ratePercent: int, years: int) → int
Where you start
function simpleInterest(principal, ratePercent, years) {
}
Worked examples
| Call | Result |
|---|---|
simpleInterest(1000, 5, 2) | 100 |
simpleInterest(10000, 10, 5) | 5000 |
simpleInterest(1234, 5, 3) | 185 |
simpleInterest(2500, 0, 10) | 0 |
Hint
Multiply all three, divide and round down.
Reference solution in JavaScript
function simpleInterest(principal, ratePercent, years) {
return Math.floor((principal * ratePercent * years) / 100);
}