Print Page | Close Window

Calculation Mystery

Printed From: Foxit's Planet PDF Forum
Category: Lets Talk PDF
Forum Name: JavaScript
Forum Description: Discussions relating to the use of JavaScript within PDF.
URL: http://forums.planetpdf.com/forum_posts.asp?TID=63
Printed Date: 12 Nov 2019 at 7:16pm
Software Version: Web Wiz Forums 11.10 - http://www.webwizforums.com


Topic: Calculation Mystery
Posted By: lolly
Subject: Calculation Mystery
Date Posted: 12 Oct 2011 at 6:13pm

I have several users in an international office who get different results with a JavaScript calculation in a form.  I have checked their preferences in Reader 7.0 and they are the same as the users who get the correct result. 

Here's my script:
 
var f = this.getField("excRate");
var g = this.getField ("Check_Amount");
if (f.value != "");
event.value = (g.value / f.value);
 
Using the following -- Amount: 190,437.50 and Rate: 32.1100, the users with the issue get 5,951.16 and the other users get the correct result of 5,951.78.
 
Any idea what could be causing this?



Replies:
Posted By: aandi
Date Posted: 12 Oct 2011 at 6:27pm
Isn't the right answer 5,930.7848 ?


Posted By: lolly
Date Posted: 12 Oct 2011 at 6:38pm
Yes, sorry -- cut and paste error on my part.  The correct amount is 5,930.78 (rounded).


Posted By: aandi
Date Posted: 12 Oct 2011 at 7:35pm
I don't have a solution but I observe that
190,437 / 32.1100 = 5,951.16 (rounded to two places).
 
Perhaps there is a clue here.
 
Are the users accessing the same file e.g. from an intranet site, or do they each have a copy which should be identical?


Posted By: lolly
Date Posted: 12 Oct 2011 at 7:40pm
Good observation.  Still mysterious but I will keep that in mind.  They did note that it appeared to them that their calculation was using an exchange rate of 32.000 which gives the same result I listed.  So it may be the format of the field(s) that may account for the issue.
 
And, in answer to your question -- they are accessing the file from the intranet so it would be the same for all.
 
I will keep you updated.


Posted By: gkaiseril
Date Posted: 12 Oct 2011 at 8:39pm

A minor syntax error, the line that reads "if (f.value != "");" should not have a ";" at the end of the line.

I would have coded the calculation as follows:
 
var f = this.getField("excRate"); // get exchange rate
var g = this.getField ("Check_Amount"); // get check amount
event.value = ""; // clear field
if (Number(f.value) != 0) {
// divisor not zero
event.value = g.value / f.value; // compute exchange
}
 
If there are other calculations on the form double check the calculation order.
 
have all of the versions of Acrbat/Reader updated?


Posted By: lolly
Date Posted: 12 Oct 2011 at 8:52pm
I will modify the script.  Thanks.  I have already confirmed the calculation order is correct. 
 
Our international offices have not updated Reader for quite some time but everyone in this office uses the same version (7.0).


Posted By: lolly
Date Posted: 13 Oct 2011 at 5:44pm
The issue was caused by the exchange rate's format being text format instead of number format.  Apparently the way the users entered the exchange rate determined whether the calculation was correct or not.  Thank you for your assistance!!



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.10 - http://www.webwizforums.com
Copyright ©2001-2017 Web Wiz Ltd. - https://www.webwiz.net