## Need help having the following formula round to the nearest hundredth

New Here ,
Oct 12, 2017

Copied

I have the following formula and it works but I would like my answer to round to the nearest hundredth.    Any help would be greatly appreciated.

var ST = this.getField("ST").value;
var SR = this.getField("SR").value;
var SS = this.getField("SS").value;
var SA = this.getField("SA").value;
var WT = this.getField("WT").value;
var WR = this.getField("WR").value;
var WS = this.getField("WS").value;
var WA = this.getField("WA").value;

if((SA == "" && SA != "0")&&(WA != "0"))
{
event.value = "TBD";
}
else
{
event.value =     (ST*WT)+(SR*WR)+(SS*WS)+(SA*WA);
}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

128

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 ## Need help having the following formula round to the nearest hundredth

New Here ,
Oct 12, 2017

Copied

I have the following formula and it works but I would like my answer to round to the nearest hundredth.    Any help would be greatly appreciated.

var ST = this.getField("ST").value;
var SR = this.getField("SR").value;
var SS = this.getField("SS").value;
var SA = this.getField("SA").value;
var WT = this.getField("WT").value;
var WR = this.getField("WR").value;
var WS = this.getField("WS").value;
var WA = this.getField("WA").value;

if((SA == "" && SA != "0")&&(WA != "0"))
{
event.value = "TBD";
}
else
{
event.value =     (ST*WT)+(SR*WR)+(SS*WS)+(SA*WA);
}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

129

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 Oct 12, 2017 0
New Here ,
Oct 23, 2017

Copied

Try:

var ST = this.getField("ST").value*100;
var SR = this.getField("SR").value*100;
var SS = this.getField("SS").value*100;
var SA = this.getField("SA").value*100;
var WT = this.getField("WT").value*100;
var WR = this.getField("WR").value*100;
var WS = this.getField("WS").value*100;
var WA = this.getField("WA").value*10;

if((SA == "" && SA != "0")&&(WA != "0"))
{
event.value = "TBD";
}
else
{
event.value =     Math.round((ST*WT)+(SR*WR)+(SS*WS)+(SA*WA))/100;
}

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 Oct 23, 2017 0
LATEST
Oct 24, 2017

Copied

Math.round is for rounding integers and does not work for rounding all floating point numbers. So if you want to round the result of the calculation you would need to multiply the result by 100 ,then apply the Math.round and then divide that result by 100.

How is your result field formatted?

It certainly is not "Number". If you want the displayed result to only display to to 2 digits rounded, the set the number of decimal places to 2.

If you want the value of the calculation set to 2 decimal places I would look at using the util.printf() method.

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 Oct 24, 2017 0