I am an intermediate user with very limited experience with scripts (I've used the "How to do (not so simple) form calculations" tutorial to learn how to get the calculations I need). I'm creating an extensive form in Acrobat 9.1.2 Pro with several calculations based on references from other cells also containing simple calculations.
I've got my custom calculation scripts correct, and they return correct values. The problem is that I have a select few calculated fields that return values with repeating decimals, when the correct value should not be such.
For example, a simple calculation ("TotalHabitatIndex"/"TotalAcres", where each is the sum of values) that should equal 0.14 is displayed as 0.1399999999999. The actual numbers being calculated are 1.4/10.
Another field with a subtraction calcuation of other calculated fields does the same thing. For example, when subtracting the values 1.1-0.19 it returns 0.9100000000000001.
What is throwing me off is that this is only occuring in one or two places, and only for certain values. In other words, the same field will correctly display 0.19 when the values being calculated are 1.9/10. The second field correctly displays 0.96 when the values being calculated are 1.15-0.19.
All fields are set to text format.
I would appreciate any ideas.
I formated the calculated fields to Number with two decimal places. In the past, this was giving me errors because of the zero and null divisor fields (which may be empty until the user fills them), but I didn't realize this was what caused the problem.
I found a script in another post to correct that problem, and the Number format now seems to work fine without errors, and I no longer have my decimal issue.
The script I used for calculating FieldA/FieldB, where FieldB is blank prior to user interaction:
// clear field value
event.value = '';
// perform division only if divisor is not zero or null
if(this.getField("FieldB").value != 0)
event.value=this.getField("FieldA").value/this.getField("FieldB").value
I still don't understand why the calculations were doing what they did, though. That kind of annoys me, but at least I found a bandaid for the problem.