Last active
March 11, 2021 02:19
-
-
Save primaryobjects/2d451c0de5e8d123cb43bc839b1a555f to your computer and use it in GitHub Desktop.
Future value calculator. FV=PV * ((1+r)^t), FV = future value, PV = present value, r = interest rate, t = compound time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fv = (pv, r, t) => { | |
// FV = PV * ((1+r)^t) | |
return pv * Math.pow(1 + r, t); | |
} | |
const interest = (pv, fv, t) => { | |
// r = sqrt[t](FV / PV) - 1 | |
return Math.pow(fv / pv, 1/t) - 1; | |
}; | |
// What is the future value of $1,000 at an interest rate of 11% for 5 years? | |
console.log(fv(1000, 0.11, 5).toFixed(2)); | |
console.log(fv(1000, 0.02, 5).toFixed(2)); | |
// What is the interest rate after 5 years for a future value of $1,685.06 from a present value of $1,000? | |
console.log((interest(1000, 1685.06, 5) * 100).toFixed(2) + '%'); | |
console.log((interest(1000, 1104.08, 5) * 100).toFixed(2) + '%'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1685.06 | |
1104.08 | |
11.00% | |
2.00% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment