javascript - AngularJS : how to properly use Math.pow in filters -
i'm new angularjs & still learning js , not skilled in maths please, gentle :)
i'm trying make loan calulator mobile app company. make 1 can auto-refresh result when value change rid of "result/ calculate" button.
i take @ angular filters, it's pretty easy build simple math formula, exponent values give me headache... i've find on stackoverflow how use filter use math.pow angular filters, can't resolve formula...
this formula have build :
m = monthly payment
k = kapital
r = rate %
n = period of payement, in years
m = [( k * r ) / 12] / [ 1 - ( 1 + ( r / 12 )) ^-n]
for 1000000 capital, 60 years , 5% rate, answer should 4386.42
var app = angular.module('app', []); function ctrl($scope) { $scope.math = window.math; };
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="app"> <div ng-controller="ctrl"> <form> <div class="item"> <label>capital</label> <input type="range" id="loan" name="loan" ng-model="capital" min="10000" max="1000000" step="10000" value="10000"> <h1>{{capital}}</h1> </div> <hr> <div class="item"> <label>number of years</label> <input type="range" id="duree" name="duree" ng-model="time" min="0" max="60" step="5" value="1"> <h1>{{time}}</h1> </div> <hr> <div class="item"> <label>rate %</label> <input type="range" id="duree" name="rate" ng-model="rate" min="1" max="15" step="0.1" value="1"> <h1>{{rate}}</h1> </div> <div class="item"> <h1>monthly payment : {{((capital * (rate /1200) * (time / 12))/12) + (capital / time) | number:2 }}</h1> <h2 > </h2> </div> </form> </div> </div>
a jsfiddle demo here : http://jsfiddle.net/_arn__/nruqk9z8/5/
could me on this, please ?
regards, arno
i think n should months (n*12):
//m = monthly payment //k = kapital //r = rate % //n = period of payement, in years var m ; var k = 1000000; var r = 0.05; var n = 60*12; var dnmntr = ( 1 + ( r / 12 )); var nmrtr = ( k * r )/12; m = nmrtr / (1-math.pow(dnmntr,-n)); console.log(m);
prints: 4386.418998606701
Comments
Post a Comment