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

Ceiling Formula Help

Gattaca714
Registered: Dec 16 2009
Posts: 25

I'm having a real difficult time figuring this out:
 
I want to use the ceiling formula to do the following:
 
User enters a number, the ceiling calculation will then round it up to the nearest 50.
 
The name of the field is: fldVbmEnvelopeOrderQty5
 
This is what I have under show "Enter", language = Javascript. Run at: Client
 
IFS.Page5.fldVbmEnvelopeOrderQty5 = Math.ceil(50)
 
Data format: Integer
Default Binding: Normal
Type: User Entered - Optional
 
Yes I've read multiple threads on it, and NO none of the links on those threads helped.

My Product Information:
LiveCycle Designer, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Here's some generic JavaScript that may help you with the calculation:

// num = 0, result = 0
// num = 1, result = 50
// num = 49, result = 50
// num = 50, result = 50
// num = 501, result = 550

var inc = 50;
var num = 89;
var result = (num % inc) ? num + (inc - (num % inc)) : num;
// result is 100


The % operator is the modulus operator in JavaScript. The code rounds up to the nearest increment if there's a remainder. Otherwise, it doesn't need to. That last line is equivalent to:

// If there's a remainder...
if (num % inc) {
result = num + (inc - (num % inc));
} else {
result = num; // No remainder
}

Gattaca714
Registered: Dec 16 2009
Posts: 25
Hi George,

Thank you for your response, I'm a bit confused on what exactly I'm suppose to do with this code your provided.

In the script editor I've inputed:

var inc = 50;
var num = 89;
var result = (num % inc) ? num + (inc - (num % inc)) : num;

When I go to preview the PDF there is no rounding up to the nearest 50 when I input a digit to the number field.

Any leads would be appreciated.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
The code was meant as an example so you could see how to perform the calculation, something you could learn from. It was not meant to be pasted and used in your form.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
BTW, you could do something like this in the validate event of the field:

var num = this.rawValue;
var inc = 50;
this.rawValue = (num % inc) ? num + (inc - (num % inc)) : num;

Gattaca714
Registered: Dec 16 2009
Posts: 25
George,

thanks for the update, and that is correct. I had value instead of this.rawValue.

Thank you very much, I did learn a lot from a couple of youtube video as well.

Rigo