Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Home
- >
- Acrobat SDK
- >
- Always round decimal up to whole number

New Here
,

Feb 13, 2018

Copy link to clipboard

Copied

How do I set a formula to always round up to a whole number?

I am not sure if this is the right place but I am creating a fillable PDF that uses a lot of formulas. This specific formula needs to always round up to the next whole number. For example, if the formula comes back as 14.01 it would still need to round up to 15. Does anyone know if I need to do a custom validation script for this? Or how to do that?

Thank you!!!

Most Valuable Participant

Since you're dividing by the value of a field you should use a custom calculation anyway, and it will also allow you to round the result.

Use this code instead:

var v1 = Number(this.getField("Text27").valueAsString);

var v2 = Number(this.getField("Text124").valueAsString);

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

else event.value = Math.ceil((v1/v2) + 1);

TOPICS

Acrobat SDK and JavaScript,
Windows

Community Guidelines

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

New Here
,

Feb 13, 2018

Copy link to clipboard

Copied

How do I set a formula to always round up to a whole number?

I am not sure if this is the right place but I am creating a fillable PDF that uses a lot of formulas. This specific formula needs to always round up to the next whole number. For example, if the formula comes back as 14.01 it would still need to round up to 15. Does anyone know if I need to do a custom validation script for this? Or how to do that?

Thank you!!!

Most Valuable Participant

Since you're dividing by the value of a field you should use a custom calculation anyway, and it will also allow you to round the result.

Use this code instead:

var v1 = Number(this.getField("Text27").valueAsString);

var v2 = Number(this.getField("Text124").valueAsString);

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

else event.value = Math.ceil((v1/v2) + 1);

TOPICS

Acrobat SDK and JavaScript,
Windows

Community Guidelines

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

paigen17377757

Feb 13, 2018
0
/t5/acrobat-sdk/always-round-decimal-up-to-whole-number/td-p/9645043
5
Replies
5

Most Valuable Participant
,

Feb 13, 2018

Copy link to clipboard

Copied

Do you use a script for the calculation, or some other means?

Community Guidelines

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

Reply

Loading...

try67

Feb 13, 2018
0
/t5/acrobat-sdk/always-round-decimal-up-to-whole-number/m-p/9645044#M24775
New Here
,

Feb 13, 2018

Copy link to clipboard

Copied

I use a simplified field notation:

(Text27/Text124) + 1

Community Guidelines

Reply

Loading...

paigen17377757

Feb 13, 2018
0
/t5/acrobat-sdk/always-round-decimal-up-to-whole-number/m-p/9645045#M24776
Most Valuable Participant
,

Feb 13, 2018

Copy link to clipboard

Copied

Since you're dividing by the value of a field you should use a custom calculation anyway, and it will also allow you to round the result.

Use this code instead:

var v1 = Number(this.getField("Text27").valueAsString);

var v2 = Number(this.getField("Text124").valueAsString);

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

else event.value = Math.ceil((v1/v2) + 1);

Community Guidelines

Reply

Loading...

try67

Feb 13, 2018
0
/t5/acrobat-sdk/always-round-decimal-up-to-whole-number/m-p/9645046#M24777
New Here
,

Feb 13, 2018

Copy link to clipboard

Copied

Ok that is really close!

For some reason, it rounds up to one more number than needed. For example, 7.63 rounds to 9.00 instead of 8 and 3.81 rounds up to 5.00 instead of 4. Any ideas on why?

Thanks for all your help!

Community Guidelines

Reply

Loading...

paigen17377757

Feb 13, 2018
0
/t5/acrobat-sdk/always-round-decimal-up-to-whole-number/m-p/9645047#M24778
paigen17377757
LATEST

New Here
,

Feb 13, 2018

Copy link to clipboard

Copied

Nevermind, I was running the formula wrong. That should work! Thank you!!

Community Guidelines

Reply

Loading...

paigen17377757

Feb 13, 2018
0
/t5/acrobat-sdk/always-round-decimal-up-to-whole-number/m-p/9645048#M24779
Using the Community
Experience League
Terms of Use
Privacy Policy
Cookie preferences
AdChoices
Language:

- Deutsch
- English
- Español
- Français
- 日本語コミュニティ
- Português

Copyright © 2020 Adobe. All rights reserved.