Skip to main content
Participant
Dec 14, 2021 5:07 PM UTC
Question

My last decimals are being set to 0. How can I show the whole answer?

Create Form > Create New > Start from a blank new sheet
I create new fields A, B, and C.  These fields are set to be a Number with 8 decimal places.

After that, set field C to be the product of A and B.

Brand new sheet, with no other edits.

 

Now go to preview and test the page.  Set the following fields:

A = 0.11111111
B = 1.00000000

 

It should be that A * B = 0.11111111  (in 8 decimal form) right?  Its not....

When I use the calulate product of A and B, I get 0.11111100

The last 2 decimal places are ignored.  This happens for all my fields. Why???

 

Is this rounding?  truncating for funzies? idk... any thoughts on how to show the whole mulitplication instead of stopping at 6 digits each time? See attached example

This topic is closed to new replies. Start a new post to keep the conversation going.

3 replies

Legend
Dec 15, 2021 6:59 PM UTC

It's certainly important though, to understand the limitations of accuracy on JavaScript. People can get in a tangle if they assume fractions are exact,  especially if working with money. 

Translate
Thom Parker
Community Expert
Community Expert
Dec 14, 2021 11:02 PM UTC

The precision of math in Acrobat is entirely dependent on two things.

1.  The capabilities of the core JavaScript version embedded in Acrobat.

2.  The ability of PDF to represent numbers.  Internally, numbers in a PDF are represented as Fixed Point. So it's gonna loose precision at some point. You'll see this after the field is refreshed from internal storage. 

 

However, the issue you are seeing isn't either one of these. You're seeing an artifact of the built-in "Product" calculation script. 

Try using a custom calculation:

 

event.value = Number(this.getField("Text4").value) * Number(this.getField("Text5").value);

 


 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Bernd Alheit
Community Expert
Community Expert
Dec 14, 2021 9:42 PM UTC

This can be the result of the decimal > binary > decimal conversion.

Translate