Round up formula help

Explorer ,
Feb 08, 2019

Copy link to clipboard

Copied

hi, i have setup my form total field to number & two decimal places so bellow formula answer showing 95.83. my request is i want to show that answer like 95.84.

1150 / 12 = 95.8333333

Also if i make another formula like (Total field value * 2), answer should be 191.68 & not 191.67

Cau pls help me to solve this issue. thanks..

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

OK, then you need to change it to a script, with this code:

var v1 = Number(this.getField("Text9").valueAsString) / 12;

event.value = roundUp(v1, 2);

And:

var v1 = Number(this.getField("Text10").valueAsString) * 2;

event.value = roundUp(v1, 2);

And place this code as a doc-level script (go to Tools - JavaScript - Document JavaScripts, and create a new item called "scripts"):

function roundUp(v, nDecimals) {

    return Math.ceil(v * Math.pow(10, nDecimals)) / Math.pow(10, nDecimals);

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

223

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 up formula help

Explorer ,
Feb 08, 2019

Copy link to clipboard

Copied

hi, i have setup my form total field to number & two decimal places so bellow formula answer showing 95.83. my request is i want to show that answer like 95.84.

1150 / 12 = 95.8333333

Also if i make another formula like (Total field value * 2), answer should be 191.68 & not 191.67

Cau pls help me to solve this issue. thanks..

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

OK, then you need to change it to a script, with this code:

var v1 = Number(this.getField("Text9").valueAsString) / 12;

event.value = roundUp(v1, 2);

And:

var v1 = Number(this.getField("Text10").valueAsString) * 2;

event.value = roundUp(v1, 2);

And place this code as a doc-level script (go to Tools - JavaScript - Document JavaScripts, and create a new item called "scripts"):

function roundUp(v, nDecimals) {

    return Math.ceil(v * Math.pow(10, nDecimals)) / Math.pow(10, nDecimals);

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

224

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
Feb 08, 2019 0
Most Valuable Participant ,
Feb 08, 2019

Copy link to clipboard

Copied

Are you using a script for this? If so, please post it.

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...
Feb 08, 2019 0
Explorer ,
Feb 08, 2019

Copy link to clipboard

Copied

hi, I'm sorry i'm not using any script & just used "simplified field notation "formulas for above to calculations.. (Text9/12) & (Text10*2). thanks..

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...
Feb 08, 2019 0
Most Valuable Participant ,
Feb 09, 2019

Copy link to clipboard

Copied

OK, then you need to change it to a script, with this code:

var v1 = Number(this.getField("Text9").valueAsString) / 12;

event.value = roundUp(v1, 2);

And:

var v1 = Number(this.getField("Text10").valueAsString) * 2;

event.value = roundUp(v1, 2);

And place this code as a doc-level script (go to Tools - JavaScript - Document JavaScripts, and create a new item called "scripts"):

function roundUp(v, nDecimals) {

    return Math.ceil(v * Math.pow(10, nDecimals)) / Math.pow(10, nDecimals);

}

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...
Feb 09, 2019 1
omanbux LATEST
Explorer ,
Feb 09, 2019

Copy link to clipboard

Copied

Thank u very much & it's work perfectly.. thanks..

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...
Feb 09, 2019 0