Copy link to clipboard
Copied
Hello everybody.
This is my first time working in Adobe with Java Script.
I have created a document in which a certain percentage should be deducted from a value.
If all values are subtracted correctly the result should be 0. The formula works fine for some numbers.
var v1 =
this.getField("Reisetage").value;
var v2 =
this.getField("k-an").value;
var v3 =
this.getField("f-an").value;
var v4 =
this.getField("m-an").value;
var v5 =
this.getField("a-an").value;
var v6 = 0;
if(v1=="ein"){
v6 = 0;
}
if(v1=="mehr"){
v6 = v2 - (v3*20/100*v2)
-(v4*40/100*v2)
-(v5*40/100*v2);
}
this.getField("Anreise").value = v6;
Copy link to clipboard
Copied
HI,
Would you be able to share the document that shows the problem, as that would make it easier for us to get to the cause?
Regards
Malcolm
Copy link to clipboard
Copied
I have adapted the file.
Maybe there will be some difficulties in understanding the file because it is in German.
The problem arises in the calculations under "Mehrtägige Reise".
Copy link to clipboard
Copied
What does you get when you change the format of the field to "None" ?
Copy link to clipboard
Copied
If you change the format to none, the programme will execute the calculation incorrectly.
I have attached the file.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hello, Malcolm,
actually it worked with the modified script. Thanks a lot, I'm already desperate about it.
Copy link to clipboard
Copied
This almost always happens when you have a field set as having a Number format and a calculation script that uses division by the value of another field. When that field is empty or zero that results in Infinity (since division by zero is not allowed), which the Number format can't handle. The solution is to add a condition to the code to check that all divisors are not zero before applying the calculation. In your case that would be the value of v2, ie. the "k-an" field.