Can anyone help me to convert this VB script to equivalent Javascript please.
PMT = ((PV - FV) * rate/ (1 - (1 + rate) ^ -(nper)))
KJYe.Name
17.2k5 gold badges50 silver badges63 bronze badges
asked Mar 18, 2011 at 15:34
-
This is already valid javascript, you should keep this in the existing threadMartin Jespersen– Martin Jespersen2011年03月18日 15:38:11 +00:00Commented Mar 18, 2011 at 15:38
-
@Martin Jespersen JavaScript doesn't have an exponentiation operator ...Pointy– Pointy2011年03月18日 15:39:23 +00:00Commented Mar 18, 2011 at 15:39
-
Sorry Martin, ^ is not a power function in JavaScript.Diodeus - James MacFarlane– Diodeus - James MacFarlane2011年03月18日 15:39:48 +00:00Commented Mar 18, 2011 at 15:39
-
1@Everyone: sorry, my bad shakes his tired friday headMartin Jespersen– Martin Jespersen2011年03月18日 15:41:11 +00:00Commented Mar 18, 2011 at 15:41
-
@Pointy @Diodeus maybe he wanted a bitwise XOR !Raynos– Raynos2011年03月18日 16:06:15 +00:00Commented Mar 18, 2011 at 16:06
1 Answer 1
Probably
var PMT = ((PV - FV) * rate / (1 - Math.pow(1 + rate, -nper)));
JavaScript numbers are always (at heart) floating-point values, so when you're dealing with money things can get somewhat weird.
answered Mar 18, 2011 at 15:39
3 Comments
dps123
Thanks Pointy, I added this values : var pmt = ((100000 - 0) * (7.5/12) / (1 - Math.pow(1 + (7.5/12), -48))); both result does not match.. any ideas please..
dps123
My objective is to do the following math : stackoverflow.com/questions/5353511/pmt-in-javascript
Pointy
The result doesn't match what?? Also, if the interest rate is 7.5%, you probably should be using 0.075 and not 7.5.
default