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

Error: arithmetic over/underflow

Gillian
Registered: Jul 10 2007
Posts: 63
Answered

Language is FormCalc

I am trying to calculate the gross margin percentage for a form. The calculation is pretty simple:

Sum(gross/SellPrice) * 100

When I switch from Designer mode to PDF Preview, I get the following error:

Error: arithmetic over/underflow

But the equation works and produces the proper result.

I have done research and found that the error id in response to the number being divided by zero.

So the question is, what is the formcalc code I need to enter in the script to deal with the divide by zero thing?

Thanks,
Gillian

-Gillian

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You can not divide by zero, so you need to add code to only allow the division when you have a non-zero divisor.

if(SellPrice ne 0) thenSum(gross/SellPrice) * 100endif

George Kaiser

Gillian
Registered: Jul 10 2007
Posts: 63
Your script calculates properly, however, I still get: Error: arithmetic over/underflow

Any ideas why I am still getting the error message?

-Gillian

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You can also check and make sure you have values to use in the calculation.
if(SellPrice ne 0 & HasValue(SellPrice)) then(gross/SellPrice) * 100elsenullendif

George Kaiser

Gillian
Registered: Jul 10 2007
Posts: 63
You rock! The second script worked and had no error messages!

-Gillian

goutah
Registered: Jun 3 2009
Posts: 4
Same question above but different scenario. i just can't seem to use your solution with my current situation. Please help.

This is my simple formula:

TOTAL / Quantity[1]

but i keep getting the same error message. So i tried the following:

if(PerSquare = 0 & HasValue(PerSquare)) then
(TOTAL/Quantity[1])
else
null
endif


No luck...
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
The error appears if you try to multipy or divide with zero, so you syntax (PerSquare = 0...) is wrong:
if(PerSquare = 0 & HasValue(PerSquare)) then(TOTAL/Quantity[1])elsenullendif

To avoid the error message you need to ensure there is no value 0 in your calculation.

if(PerSquare ne 0 & HasValue(PerSquare)) then(TOTAL/Quantity[1])elsenullendif

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You are using the set value operator and not one of the equality operators in the logical test. Also your divisor is "Quantity[i]" and you are not checking if that value is zero.

It would also help if you could provide the exact error text.

In preview, I receive the following error:

Quote:
Script failed (language is formcalc; contest is
sfa[0].form[0].#subform[0].UnitPrice[0])
script=if(PerSquare = 0 & HasValue(PerSquare)) then
(TOTAL/Quantity[1]
else
null
endif
Error: syntax error near token '=' on line 1 column 14.
Clearly the '=', set operator, is causing the error.

After replacing that operator with one of the equality operator, then I get the underflow/overflow error when the 'Quantiy[1]' field is zero or null.

George Kaiser

goutah
Registered: Jun 3 2009
Posts: 4
My error message is:

Error: arithmetic over/underflow
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Your divisor is zero or you are trying to divide by zero!

Are you sure you posted the correct code?

You need to check that 'Quantity[1]' has a value and 'Quantity[1]' is not zero or null.

To see what is happening try:
xfa.host.messageBox(Concat("Quantity[1]: ", Quantity[1], " PerSquare: ", PerSquare, " TOTAL / Quantity[1]: ", TOTAL / Quantity[1]) )// corrected to equality operator '=='if(PerSquare == 0 & HasValue(PerSquare)) thenTOTAL / Quantity[1]elsenullendif

George Kaiser

angielynch
Registered: Apr 8 2010
Posts: 11
I am new to LiveCycle. I am having an issue calculating some percentages. Basically I have 6 fields plus a total field. I need to have a percentage calculated according to the total of these 6 fields, the formulas I have actually work, but I get this error when I open the file. I tried all last night to find the answer but I can figure it out. I would be happy to send the PDF to anyone that could help me out. PLEASE I am losing my mind!!!!
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
When you open your form the value of the fields is a null value, you may need to test of the total being a non-null value and a non-zero value before you perform your division.

George Kaiser

angielynch
Registered: Apr 8 2010
Posts: 11
This is actually the formula I have in the total field NO1 + NO2 + NO3 + NO4 + NO5 + NO6
(each in each of these fields the person enters an amount, then it it added in the total and then six percentages are calculated) then I have another formula (NO1*100)/Total to calculate the percentage. Once again, I have NO clue what I am doing here, this was just thrown at me because nobody else knew or wanted to do it :) could I send it to you?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You are not using an 'if' statement to see if the variable 'Total' has a non zero value and is not equal to a Null value.

if (Total ne Null and Total ne 0) then// Total is not a null value and does not have a zero value(NO1 * 100) / Totalelse// either null or zero so show nothingNullendif

Or one could use the 'HasValue()' function to see if 'Total' has a value and test for 'Total 'not equal to zero.
if (HasValue(Total) & Total <> 0) then// Total is not a null value and does not have a zero value(NO1 / Total) * 100else// either null or zero so show nothingNullendif

George Kaiser

angielynch
Registered: Apr 8 2010
Posts: 11
That worked! THANK YOU SO MUCH!!!!!!!!!!!!!! I would have NEVER figured that out!!!!
issamich
Registered: Jan 21 2011
Posts: 1
Hi, I have the same Error with this formula:

if(px[0] ne 0 & HasValue(px[0])) then
((real[0]-px[0])/px[0])*100
endif

But in my case, only appears when the PX variable has a value greater than or equal to 10,000,000, on the other hand, if the value is, for example 9,000,000, does not mark any Error.

Any ideas?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You are probably getting a result value that exceeds the IEEE floating point format from being displayed.

George Kaiser