Reputation: 283
I'm trying to create a payday loan calculation and I've had help on math.stackexchange.
I've been given a formula to calculate an APR figure.
I have an amount I want to loan £100 I want to pay this back in 14 days. Interest for this loan is 15% The fee for this service is 0.20p per day. From this I calculate the fee to be £17.80.
(100+100×0.15+0.2×14100)365.25/14−1≈70.80
So effectively the APR will be 7080%
How would I calculate this answer in Javasript to two decimal places?
I currently have this but I'm getting the wrong figure.
function update() {
$interest = 0.15 ;
$perday = 20 ;
$amount1 = $("#amount").val();
$amount1 = parseInt($amount1, 10) || 100;
$dayscount = $("#days").val();
$amount2 = parseInt($amount1) + $interest * parseInt($amount1) + (parseInt($dayscount) * ($perday/100));
$apr = (($amount2-$amount1 / $amount1 ) / ((parseInt($dayscount)/365.25) * 100));
$("#amount").text($amount1);
$("#amount2").text($amount2);
$("#amount3").text(parseFloat($amount2-$amount1).toFixed(2));
$("#amount4").text(parseFloat($apr).toFixed(2));
}
Thanks
Upvotes: 0
Views: 1666
Reputation: 6290
Change this line
$apr = (($amount2-$amount1 / $amount1 ) / ((parseInt($dayscount)/365.25) * 100));
to this
$apr = Math.pow($amount2 / 100, 365.25 / $dayscount) - 1;
It will give you 70.80
P.S. In Javascript, developers commonly put $ in front of a variable to signal it is a jQuery object. No need to do it here.
Upvotes: 1