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

Need help with rounding in simplified field notation...PLEASE!

bsharp
Registered: Oct 20 2009
Posts: 6

Hello, I am working on a number of forms and I need a few fields to round up/down to the nearest one hundredth. I have the math part working just can not figure out the rounding part. my current notation is "ofpgs/PPI" I need the value of this to round accordingly. Could anyone point me in the right direction? TIA

My Product Information:
Acrobat Pro 8.1.6
bsharp
Registered: Oct 20 2009
Posts: 6
Alright, I figured out I need the custom calculation script but how do I incorporate x=Math.round (I am new at this obviously) and can it get it to go to a hundredth?
bsharp
Registered: Oct 20 2009
Posts: 6
I am this far and it seems to be working however it is not rounding to the nearest hundredth. Can someone steer me right? Here is what I have

this.getField("Bulk").value=Math.round(100*this.getField("ofpgs").value)/(this.getField("PPI").value)/100;
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Have you looked at the results of each operation of the math?

You want to round the result of the value of 'ofpgs / PPI' and you do want to round '100 * ofpgs'. You also have to deal with the issue of division by zero.

console.show();console.clear();var fOfpgs = this.getField("ofpgs").value;console.println('ofpgs = ' + fOfpgs);var fPPI = this.getField("PPI").value;console.println('PPI = ' + fPPI);console.println('100 * ofpgs = ' + (100 * fOfpgs) );console.println('Math.round(100 * fpgs) = ' + Math.round(100 * fOfpgs) );console.println('Math.round(100 * ofpgs) / PPI) = ' + (Math.round(100 * fOfpgs) / fPPI) );console.println('Math.round(100 * ofpgs) / PPI / 100 = ' + (Math.round(100 * fOfpgs) / fPPI / 100) );console.println('Math.round(100 * ( ofpgs / PPI) ) / 100 = ' + ((Math.round(100 * fOfpgs / fPPI) / 100)) );if (this.getField("PPI").valueAsString == 0) {console.println('You can not divide by zero!');} event.value = '';if (this.getField("PPI").valueAsString != 0) {var fBulk = this.getField("ofpgs").value / this.getField("PPI").value;event.value = Math.round(100 * fBulk ) / 100;}

George Kaiser

bsharp
Registered: Oct 20 2009
Posts: 6
Alright I will look into that, I think I am on the right path now. Thanks for the input