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

Complex computation with rounding and minimum value limit.

todd0168
Registered: Oct 1 2009
Posts: 13
Answered

I have a form that I am trying to create a calculation on to save time in future filling of this form. I will have to use this form multiple times for various companies. Here is what I have leading up to the field that I need help with the calculation on:

Field 1 is Net Assets End of Period

Field 2 is Net Assets Used for Activities

Field 3 is a calculation of Field 1 - Field 2 with a limit to not go below 0

Field 4 is the one I need the calculation on. It is Field 3 * .0001 rounded to whole dollars and if it's less than $5 should be $0.

I'm pretty sure I could use the info from the Field 3 calculation to get the limit to display 0, but how do I get it to round if it actually calculates?

-edit-

Here is what I have so far:

var a = this.getField("SubNetAss").value;
var b = .0001;
event.value = a * b
if(event.value < 5) event.value = 0;

This calculates correctly and displays $0 for anything under $5, but how do I round this off to whole dollars?

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
A quick search turned up [url=http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=24996]Sum and Multiply by tax rate[/url]. I prefer to use the 'util.print()' method as it rounds in a more consistent manner.

George Kaiser

todd0168
Registered: Oct 1 2009
Posts: 13
Yes I did see that in my searching, but unfortunately I could not understand what most of that meant.

Would I use the following then to get it to round to whole dollars? The code on that topic you linked to talks about the util.print but the top part of that code makes absolutely no sense to me at all and I have no idea how I would incorporate that into my code.


var a = this.getField("SubNetAss").value;
var b = .0001;
event.value = Round(a * b, 0)
if(event.value < 5) event.value = 0;
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
You need to have the user defined 'Round()' function available to your form. The best approach is to place this code in the PDF form as a document level function so it is initialized and made available when the form if opened.

function Round(nValue, iDecimal) {/*function to perform the rounding of a passed value to the passed number of decimal places*/// use the  util.printf method to round the nValue to iDecimal placesreturn Number( util.printf('%,1 .' + Math.floor(iDecimal) + 'f', Number(nValue) ) );} // end of Round function

[url=http://www.acrobatusers.com/tutorials/2006/document_actions]"Where is" Series, Entering Document Actions[/url] by Thom Parker

George Kaiser