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

Round up - Round down - Custom Calculation Script?

keyon
Registered: Feb 26 2008
Posts: 19

What I'm trying to do is take the value of text field A - and either round up or round down - and display the new number in field B.

From what I understand, the following should be used for rounding numbers:

Math.round
Math.floor
Math.ceil

What I don't know is how to implement these in a script that I would paste into the "custom calculation script" box. Or perhaps I could us the "simplified field notation"?

Thanks

My Product Information:
Acrobat Pro Extended 9.1.3, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
All of the above are methods of the [url=https://developer.mozilla.org/en/A_re-introduction_to_JavaScript]JavaScript[/url] [url=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Math]Math object[/url].

[url=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Math/ceil]Math.ceil(x)l[/url]
[url=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Math/floor]Math.floor(x)[/url]
[url=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Math/round]Math.round(x)[/url]

George Kaiser

keyon
Registered: Feb 26 2008
Posts: 19
Thanks...but are you saying I should be able to paste these exact pieces of code in the "simplified field notation" or the "custom calculation script" boxes in Acrobat?

I've tried, but it doesn't seem to work.

Am I missing a portion of code that needs to accompany Math.cei (x) ?

Thanks
try67
Expert
Registered: Oct 30 2008
Posts: 2398
1. You can only use it in the custom calculation script.
2. It's not Math.cei it's Math.ceil
3. You need to replace x with the value you want to round up/down.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

keyon
Registered: Feb 26 2008
Posts: 19
Thanks...but still not working for me.

Here's what I'm trying to do:

1. I have a text field box named A1 with the value 3.5
2. I have another text field box named A2 with the custom calculation script - Match.ceil (A1)
3. I want text field box named A2 to display the value of A1 rounded up to 4.

Does that make sense?

thanks
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You can't access the value of A1 like that, you need to use the proper JavaScript method, which is:
this.getField("A1").value
So the total script is:
this.getField("A2").value=Math.ceil(this.getField("A1").value);

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

keyon
Registered: Feb 26 2008
Posts: 19
try67 wrote:
You can't access the value of A1 like that, you need to use the proper JavaScript method, which is:
this.getField("A1").value
Thanks, try67...

Can tell me how to combine -- Math.ceil(x) -- with -- this.getField("A1")

I don't know how to write Javascript (yet) - I'm just trying to figure out what entire code string should look like - the actual code that I would paste into the custom calculation script box.

thanks
try67
Expert
Registered: Oct 30 2008
Posts: 2398
I've edited my previous message with the entire script you need.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

keyon
Registered: Feb 26 2008
Posts: 19
Thanks for adding that....let me give it a try.
keyon
Registered: Feb 26 2008
Posts: 19
whoa......!!!
I think it's working!!!!
Yahoo.

thanks for your help.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
keyon wrote:
Thanks...but are you saying I should be able to paste these exact pieces of code in the "simplified field notation" or the "custom calculation script" boxes in Acrobat?I've tried, but it doesn't seem to work.

Am I missing a portion of code that needs to accompany Math.cei (x) ?

Thanks
Sorry about the dropped letter.

All of the blue underlined words are links to the JavaScript documentation so you can read the syntax, parameters, descriptions, and examples of each method and the version 1.5 JavaScript Reference manual.

You might want read Thom Parker's [url=http://www.acrobatusers.com/tutorials/2006/form_calculations]How to do (not so simple) form calculations[/url] and look at some of the eSeminars on demand.

George Kaiser

RudyPT
Registered: Oct 26 2009
Posts: 9
Hi - I am developing a PDF, and have been able to get by with "simplified field notations" performed for me up to this. Unfrotuantely, now I am stuck and I do not know where to turn for help. The Javscript world is forign to me. Thus, I apologize upfront for my ignorance.

This is what I am trying to accomplish. I wish to have field "Text34" equal a rank number 0, 1, 2, or 3 based upon the data (number) entered into field "Text15"

in other words, if "Text15" were greater than or equal to 3.75 then "Text34" would equal 3. Or, if "Text15" is less than or equal to 3.25 then "Text34" would equal 0.

I hope this makes sense? I would greatly appreciate any help anyone might be willing and able to offer.

Thanks, Rudy
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi RudyPT,

You should start a new thread for this....

Dimitri
WindJack Solutions
www.pdfscripting.com
www.windjack.com
RudyPT
Registered: Oct 26 2009
Posts: 9
Done -thanks for the advice. :)