These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Limiting Decimal places

claramitsahne
Registered: Nov 10 2008
Posts: 31

Is it possible to limit the number of decimal places in a field that has been calculated?
I have selected 'Decimal Places: 2' in the Text Field Properties section, but when you click into the box a string of numbers appear. The calculation is correct, but the extra numbers are not required because it is a form for simple financial records.
Thanks in advance
C

My Product Information:
Acrobat Pro 8.1.2, Macintosh
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Yes, but this will force rounding of the value which may impact other calculations.

You can use the "util.printf(cFormat, arguments)" method.

The "cFormat" string consist of the following options:

%[,nDecSep][cFlags][nWidth][.nPrecision]cConvChar

The example script:

var n = Math.PI * 100; // a convenient value
console.println("PI * 100 = " + n); // show full number
var dRounded = util.printf("%.2f", n); // round to 1/100's
console.println("Rounded float format:" + dRounded); // display result

More information is contained in the Acrobat JS API Reference.

George Kaiser

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Also, calculated fields should normally be set to read-only so that a user cannot attempt to interact with them.