I am making a compound interest calculator, and want to input minimum 3 input fields from "amount", "compound interest", "time" and "rate". I can calculate the remaining field by the data provided but the problem comes when I have to find the value of "time".
Now, take a simple example of p = $1000, r =10% pa and A = 1210. I know that the answer for time is 2 years, but I have to use a formula. After I searched, I got formula:
t = log10(A/P) / (n*log10(1+R/n))
Here n is how much times I have to compound annually, i.e. 1 times so it is 1. So formula will become
t= log10(1210/1000)/1*log10(1+10/1)
which ultimately is log10(1.21)/log10(11)
.
Now putting it in JavaScript, const t = Math.log10(1.21)/Math.log10(11)
gives answer as 0.079494864421745, while the actual time is 2.
What am I doing wrong?