These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Arithmetic Underflow error

phornung2
Registered: Mar 2 2010
Posts: 23
Answered

I'm trying to divide the sum of three fields, as well as set a maximum on the total. My current formcalc script looks likes this, but I keep getting an arthimetic over/underflow error. I just haven't had any luck trying to figure this out. It must have something to do with a null value. But I'm just not sure. Could someome possibly take a look and offer some help? Thanks so much.
 
var Total = Sum(Field1,Field2,Field3/Field4)
if (Total lt 225) then $ = Total else $ = 225 endif
 

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
So is the sum divided by "Field4"? or is just "Field3" divided by "Field4"? Is Field4 ever blank or 0? Dividing by zero can of course be a problem.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

phornung2
Registered: Mar 2 2010
Posts: 23
Yes, the sum of Field1, Field2, Field3 is divided by Field4. I should use Sum ((Field1,Field2,Field) / Field4)). There could be a chance that Field 4 is zero or left blank.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You need to do two things in the code. Test Field4 to make sure it's not zero,and divide the sum by Field4.

var Total = 0
if(Field4 > 0) then
Total = Sum(Field1, Field2, Field3)/Field4
endif


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Accepted Answer
This assume the divisor will not be less than 0. If it is less than zero you might try:

var Total = Sum(Field1,Field2,Field3)
if(Field4 ne 0 and Field4 ne null) then
Total = Total / Field4
endif

if(Total lt 225) then
$ = Total
else
$ = 225
endif

George Kaiser

phornung2
Registered: Mar 2 2010
Posts: 23
Thank you both for all the help. This worked perfectly. Again, thank you!