
1. Re: Subtracting in Adobe Acrobat XI not working properly.
try67 Jan 26, 2016 2:35 PM (in response to toreyb81942662)Yes, this is a general problem in JavaScript, known as a floating point error. There are several ways around it. One of which is to force the result to round to a specific fixed length by using the toFixed method, like this:
(107.7101.5).toFixed(1)
This will return "6.2", but as a string. You can then convert it back to a number using the Number object constructor, for example.

2. Re: Subtracting in Adobe Acrobat XI not working properly.
George_Johnson Jan 27, 2016 1:01 AM (in response to toreyb81942662)You should also look into using the util.printf method instead of toFixed. Consider the following:
util.printf("%.2f", 0.045)
(0.045).toFixed(2)
The first gives "0.05" while the second gives "0.04".
While for these:
util.printf("%.2f", 0.035)
(0.035).toFixed(2)
The first gives "0.04" and the second gives "0.04".
The point is you need to understand exactly how rounding is done with whatever method you choose.

3. Re: Subtracting in Adobe Acrobat XI not working properly.
toreyb81942662 Jan 27, 2016 6:37 AM (in response to George_Johnson)For this in particular, I'm subtracting two field values with one decimal place and anything other than xx.9xx.4 gives inaccurate responses. I need a way to make this calculated value a set number so that I can use it to calculate another field value. My exact problem with the way it is now is that the numbers calculated are 10.75.2=5.499998 and 10.95.4=5.5. When I subtract these numbers in another field i get a negative value instead of simply 0 along with an error message about the negative number.

4. Re: Subtracting in Adobe Acrobat XI not working properly.
Test Screen Name Jan 27, 2016 7:42 AM (in response to toreyb81942662)That is how numbers are and you have to allow for it. The result is not incorrect, the expectation is.
fractional numbers are not stored exactly. This vital fact is often overlooked. When dealing with money, for instance an accountant would expect you to work with fractional cents as whole numbers

5. Re: Subtracting in Adobe Acrobat XI not working properly.
try67 Jan 27, 2016 8:32 AM (in response to Test Screen Name)I don't think you can say the result is not incorrect. It is mathematically incorrect, even though it is expected, considering the limitations of how numbers are stored in some programming languages. That doesn't change that fact that it's not what it should be.

6. Re: Subtracting in Adobe Acrobat XI not working properly.
Test Screen Name Jan 27, 2016 8:35 AM (in response to try67)I disagree. The specification of JavaScript says that you are working with floating point numbers. The properties of floating point numbers are well understood and unchanging. That is therefore what is documented, and when it does this, it is 100% correct. Again, it is expectations that JavaScript math is the same as school math that is the problem.

7. Re: Subtracting in Adobe Acrobat XI not working properly.
try67 Jan 27, 2016 8:58 AM (in response to Test Screen Name)There aren't multiple kinds of math. 10.75.2=5.499998 is a false statement. If the developers of JS want to reinvent how calculations are done then they should have chosen new symbols for their new type of "math" and not use numbers. I understand the limitations and the fact that it's welldocumented and all of that, but it still doesn't make it a correct result.

8. Re: Subtracting in Adobe Acrobat XI not working properly.
gkaiseril Jan 27, 2016 10:03 AM (in response to try67)And then there is a branch of mathematics called Actuarial Science. If one allows for a margin of error the calculation is correct.
Also one is converting decimal values to binary values and it is a well known fact that not all decimal values convert to rational binary values. As pointed out there are methods to reduce or eliminate these errors.

9. Re: Subtracting in Adobe Acrobat XI not working properly.
George_Johnson Jan 27, 2016 10:55 AM (in response to toreyb81942662)I would suggest the following custom calculation script:
(function () {
// Get the field values, as numbers
var v1 = +getField("text1").value;
var v2 = +getField("text2").value;
// Perform the calculation and round to the nearest 100th
event.value = util.printf("%.2f", v1  v2);
})();
Rounding to the nearest 1000th or 10,000th will prevent the problem you're seeing as well.
One particular problem occurs when the result of the calculation is a number very close to zero so that the result is represented in exponential notation (e.g., 1.234e12). Since the builtin formatting routines don't correctly deal with this result, you'll get an error. The way to deal with this is to round the result of the calculation so that a number like 1.234e12 is rounded to 0.00 or whatever precision you require.

10. Re: Subtracting in Adobe Acrobat XI not working properly.
Bernd Alheit Jan 27, 2016 12:43 PM (in response to toreyb81942662)You can use a library like this: