Highlighted

Round Down Calcuation in PDF Form

New Here ,
Aug 26, 2020

Copy link to clipboard

Copied

I am trying to create a calculation in my PDF form that will calcualte: 

 

FIELD2 = (FIELD1 - 10) / 2  

 

I want the total to round down. For example: 

(19-10) / 2 = 4.5

The answer would populate as 4 instead of 4.5. 

 

I also need the answer to show as negative if the answer is negative and to show as 0 or blank if nothing is in the original field. I was able to locate this scipt: 

var result = (Number(this.getField("ModuleWidth").valueAsString)-12)/180;

event.value = Math.floor(Math.abs(result));

But the script is not producing a negaitve # or blank/0 when doing the calculation. 

 

Can anyone help? 

 

TOPICS
Comment review and collaborate PDF, Create PDFs, PDF forms

Views

39

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Round Down Calcuation in PDF Form

New Here ,
Aug 26, 2020

Copy link to clipboard

Copied

I am trying to create a calculation in my PDF form that will calcualte: 

 

FIELD2 = (FIELD1 - 10) / 2  

 

I want the total to round down. For example: 

(19-10) / 2 = 4.5

The answer would populate as 4 instead of 4.5. 

 

I also need the answer to show as negative if the answer is negative and to show as 0 or blank if nothing is in the original field. I was able to locate this scipt: 

var result = (Number(this.getField("ModuleWidth").valueAsString)-12)/180;

event.value = Math.floor(Math.abs(result));

But the script is not producing a negaitve # or blank/0 when doing the calculation. 

 

Can anyone help? 

 

TOPICS
Comment review and collaborate PDF, Create PDFs, PDF forms

Views

40

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 26, 2020 0
Adobe Community Professional ,
Aug 26, 2020

Copy link to clipboard

Copied

Remove the Math.abs.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 26, 2020 1
Engaged ,
Aug 26, 2020

Copy link to clipboard

Copied

Try and see if this works for you:

var result = Number(this.getField("ModuleWidth").valueAsString);
var res = (result-12)/180;
if(result == ""){
event.value = "0";
}else event.value = Math.floor(res);

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 26, 2020 0
Most Valuable Participant ,
Aug 27, 2020

Copy link to clipboard

Copied

Small correction: If you use the Number constructor the result can't be a string. So if you don't want to display anything if the ModuleWidth field is empty then use this code:

 

(EDIT: Fixed small mistake in code)

 

 

var v = this.getField("ModuleWidth").valueAsString;
if (v == "") {
	event.value = "";
} else {
	var res = (Number(v)-12)/180;
	event.value = Math.floor(res);
}

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 27, 2020 0
Adobe Community Professional ,
Aug 27, 2020

Copy link to clipboard

Copied

Why the second else?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 27, 2020 0
try67 LATEST
Most Valuable Participant ,
Aug 27, 2020

Copy link to clipboard

Copied

I removed it already... It was left over from the original code which I edited.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 27, 2020 0