• Calculated field that rounds down, but if the resu...

# Calculated field that rounds down, but if the result is 0, show the result as 1 instead

Community Beginner ,
Jun 22, 2022 Jun 22, 2022

Copied

Hello! I have a form that has multiple calculations, and one thing I've been asked to do is to divide one field by another and show the result in a third field. This third field should round down to the nearest whole number. However if the nearest whole number is 0, the field should show 1 as the result. I've looked online for javascript to put in the Custom Calculation Script window, but nothing has worked so far. Can someone help me figure this out?

TOPICS
JavaScript , PDF forms

Views

51

Likes

Report

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

Adobe Community Professional , Jun 22, 2022 Jun 22, 2022

Lets say you have "Field A", "Field B" and "Field C", you can use this as custom calculation script of "Field C":

var a = Number(this.getField("Field A").value);
var b = Number(this.getField("Field B").value);
if(b != 0)
var x = Math.floor(a/b);
if(x==0)x=1;
event.value = (a&&b)?x:"";

Likes

4 Replies 4
Jun 22, 2022 Jun 22, 2022

Copied

Hi there

Hope you are doing well and sorry for the trouble.

The workflow that you are trying to achieve is possible using JavaScript. For more information please check the help pages listed below:

https://acrobatusers.com/tutorials/javascript_console/

Regards

Amal

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Jun 22, 2022 Jun 22, 2022

Copied

Thank you for posting the links, Amal!

Likes

Report

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

Copied

Lets say you have "Field A", "Field B" and "Field C", you can use this as custom calculation script of "Field C":

var a = Number(this.getField("Field A").value);
var b = Number(this.getField("Field B").value);
if(b != 0)
var x = Math.floor(a/b);
if(x==0)x=1;
event.value = (a&&b)?x:"";

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Jun 22, 2022 Jun 22, 2022

Copied

LATEST

Nesa - Thank you so much!! This works perfectly and you laid it out in an easy to read and modify format! š

Likes

Report

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