[thelist] JScript v VBScript

Michael Galvin mpgalvin at eircom.net
Tue Jan 29 15:10:00 CST 2002


I have a little problem.  I've 'stolen' a bit of VBScript from a site which
works out the monthly financing on a motor loan.  It's written in VBScript,
so it only works on Windows machines (I assume - it certainly doesn't work
on IE Mac).

So I decided to convert it to JScript.  No problems technically, but there
seems to be a massive difference between how VBScript works out maths
figures and how JScript handles it.

VBScript:
MthFullCredit=int((Prin*MonthRate)/(1-(1+MonthRate)^(-1*NumPayments))*100)/1
00

JScript:
MthFullCredit=Math.ceil((Prin*MonthRate)/(1-(1+MonthRate)^(-1*NumPayments))*
100)/100;

Exact same code (apart from int becoming Math.ceil).  But the result of the
VBScript is 567.11, while JScript gives me -3.7!  Bit of a difference.  I've
narrowed it down to the

(1-(1+MonthRate)^(-1*NumPayments))*100

section of the code, for which VBScript gives 24.4 odd and JScript
returns -3600.  I assume it's the order in which the 2 languages do each
part of the calculation.  Does anybody know what I'm talking about, and help
me work out the order that VBScript uses so that I can 'force' JScript to do
the same thing...?

(Just so you know, I haven't a clue what the script is doing to work out
MthFullCredit, and every time I change it, it breaks)




More information about the thelist mailing list