dividing two fields

Explorer ,
Sep 01, 2017

Copy link to clipboard

Copied

I have three fields. Two of them are input fields. Field1 is to enter the foot measurement of length of board. Field2 is to enter the specific size I want to get out of Field1. Like for example 8' / 3' = 2pcs. I don't want the scrap amount, just to show 2pcs. I have the following script to do the division,

var v1 = +this.getField("Field1").value;

var v2 = +this.getField("Field2").value;

if (v2==0) event.value = "";

else event.value = v1 / v2;

the script works to do the division, but it rounds up. Unless I select one decimal place under the Number pane. But, I don't want that result. I would just like to see the whole number. Not the number with the decimal place. Does anyone know the javascript to enable me to do the calculation the way I'd like? Please let me know. Thanks.

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

You can use:

Math.round(v1/v2-0.5);

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

195

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

dividing two fields

Explorer ,
Sep 01, 2017

Copy link to clipboard

Copied

I have three fields. Two of them are input fields. Field1 is to enter the foot measurement of length of board. Field2 is to enter the specific size I want to get out of Field1. Like for example 8' / 3' = 2pcs. I don't want the scrap amount, just to show 2pcs. I have the following script to do the division,

var v1 = +this.getField("Field1").value;

var v2 = +this.getField("Field2").value;

if (v2==0) event.value = "";

else event.value = v1 / v2;

the script works to do the division, but it rounds up. Unless I select one decimal place under the Number pane. But, I don't want that result. I would just like to see the whole number. Not the number with the decimal place. Does anyone know the javascript to enable me to do the calculation the way I'd like? Please let me know. Thanks.

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

You can use:

Math.round(v1/v2-0.5);

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

196

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
Sep 01, 2017 0
Most Valuable Participant ,
Sep 01, 2017

Copy link to clipboard

Copied

Change the format of the field to None.

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...
Sep 01, 2017 0
Explorer ,
Sep 01, 2017

Copy link to clipboard

Copied

I tried changing the Format to None and I get a decimal number. What I want is a single number. That's the part I don't know how to do. And, I've searched the internet for the answer. How can I have the result come back as a whole number? Like this, 20/9=2 not 2.22222222. Will this be possible? Changing the Format to None isn't gonna work for me.

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...
Sep 01, 2017 0
Adobe Community Professional ,
Sep 01, 2017

Copy link to clipboard

Copied

You can use:

Math.round(v1/v2-0.5);

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...
Sep 01, 2017 0