Skip to main content
Participant
December 14, 2021
Question

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

  • December 14, 2021
  • 3 replies
  • 565 views

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 has been closed for replies.

3 replies

Legend
December 15, 2021

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. 

Thom Parker
Community Expert
Community Expert
December 14, 2021

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);

 


 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Bernd Alheit
Community Expert
Community Expert
December 14, 2021

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