Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Need help with a conditional calculation...

Avatar

Level 4

I have a field that the user chooses as either a percentage of their income, or as a dollar amount. Based on what they choose, I'm using actions to show/hide the unchecked field. When using the percentage, it takes the annual salary that they input and divides it by the percentage they input, and displays that dollar amount in another field. Problem is I get an "arithmitic over/underflow" error. And it also seems to be keeping the values, ie; if I select "Dollar" and input an amount, but then uncheck "Dollar" and selet "Percent", it keeps the dollar amount in the equation. Hope that makes sense.

UPDATE:

Upon thinking further, if I could just have it to where if I was to input a value into the percent box, and there was a value present in the dollar field, it would delete the value from dollar and vice versa that would be great!

UPDATE 2:

I have the previous issue solved, but I get the following errorCapture.PNG

The only thing I can think is that by default, I have the anualSalary field set to a default of $1.00. It does the calculation correctly, but I keep geting that error. Any ideas?

0 Replies

Avatar

Level 10

Hi,

the arithmetic over/underflow happens if any of the values used in a script is 0.

You can wrap you script in a if expression to avoid this problem.

if (annualSalary gt 0 and percent gt 0) then

     $ = annualSalary / percent / 24

}

Avatar

Level 4

Sorry, but I can't seem to get this to work. I have 3 fields, the annualSalary field, the percet field, and the total field where I put the expression in the calculate function. I used FormCalc as the language and get a syntax error. Is it JavaScript? Am i missing a needed field? Sorry for my newbness

Message was edited by: Syrax12

Avatar

Level 10

Ahhh... sorry,

I mixed up FormCalc with JavaScript.

if (annualSalary gt 0 and percent gt 0) then

     $ = annualSalary / percent / 24

endif