Created
January 23, 2013 23:13
-
-
Save ghalimi/4615572 to your computer and use it in GitHub Desktop.
NPER Function
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
// Copyright (c) 2012 Sutoiku, Inc. (MIT License) | |
function NPER(rate, payment, present, future, type) { | |
// Initialize type | |
var type = (typeof type === 'undefined') ? 0 : type; | |
// Initialize future value | |
var future = (typeof future === 'undefined') ? 0 : future; | |
// Evaluate rate and periods (TODO: replace with secure expression evaluator) | |
rate = eval(rate); | |
// Return number of periods | |
var num = payment * (1 + rate * type) - future * rate; | |
var den = (present * rate + payment * (1 + rate * type)); | |
return Math.log(num / den) / Math.log(1 + rate); | |
} |
thanks man your a life saver
try passing
NPER(0/12, 200, -3000, 0)
this function fails
i have rate: 3.25% ,payment:5000,present:150000,
why does it return a negative value . How can i get no of months from this or the amount with interest
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn't seem to work when rate is 0