[thelist] JScript v VBScript

Richard Bennett richard.bennett at skynet.be
Tue Jan 29 15:47:01 CST 2002


Hi,
The correct formula in javascript should be:

MthFullCredit=parseInt((Prin*MonthRate)/(1-Math.pow((1+MonthRate),(-1*NumPay
ments)))*100)/100;

Cheers,
Richard.

----- Original Message -----
From: "Michael Galvin" <mpgalvin at eircom.net>
To: <thelist at lists.evolt.org>
Sent: Tuesday, January 29, 2002 10:12 PM
Subject: [thelist] JScript v VBScript


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)

--
For unsubscribe and other options, including
the Tip Harvester and archive of thelist go to:
http://lists.evolt.org Workers of the Web, evolt !





More information about the thelist mailing list