• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Odd to even rounding script

Community Beginner ,
Jan 22, 2019 Jan 22, 2019

Copy link to clipboard

Copied

We utilize a non conventional way of rounding and I would like to format the calculated fields in my form to this rounding method:

Example: 0.45 rounds to 0.4

                0.35 rounds to 0.4

It's called "Odd to Even" rounding. If the place being rounded (tenths place) has a five in the hundredths place and the number in the tenths place is even it rounds down and if the number in the tenths place is odd it rounds up.

Any help would be greatly appreciated. Thanks!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

452

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
community guidelines

correct answers 1 Correct answer

Community Beginner , Jan 23, 2019 Jan 23, 2019

Thank you Thom Parker and George_Johnson​! Your direction has solved my issue. ​That link George shared did the trick once Thom pointed out that it had to be a document script. Then all I had to do was utilize that function in the custom formatting like I would anything else.

Votes

Translate

Translate
Community Expert ,
Jan 22, 2019 Jan 22, 2019

Copy link to clipboard

Copied

You'll need to write your own rounding function, and custom calculation scripts. Do you have any programming experience?

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Community Beginner ,
Jan 22, 2019 Jan 22, 2019

Copy link to clipboard

Copied

Not really. I have just begun delving into pdf programming this month. I've done a few things like auto imputing a future date and basic custom calculation. I'm learning as I go.

Votes

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
community guidelines
Community Expert ,
Jan 22, 2019 Jan 22, 2019

Copy link to clipboard

Copied

The rounding function should be a document script, so it's defined once and accessible to all other scripts in the PDF.

Did you want the actual value of the field to be rounded? or just how the value is displayed?  This is important if the value is used in other calculations.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Community Beginner ,
Jan 22, 2019 Jan 22, 2019

Copy link to clipboard

Copied

I'd like the displayed value to be rounded not the actual value because it is used in other calculations.

Votes

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
community guidelines
LEGEND ,
Jan 22, 2019 Jan 22, 2019

Copy link to clipboard

Copied

It's commonly known as "Banker's rounding", which may be helpful if you do a search for JavaScript code that accomplishes it, e.g.: Gaussian/Banker's Rounding in JavaScript · GitHub

Votes

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
community guidelines
Community Beginner ,
Jan 23, 2019 Jan 23, 2019

Copy link to clipboard

Copied

Thank you Thom Parker and George_Johnson​! Your direction has solved my issue. ​That link George shared did the trick once Thom pointed out that it had to be a document script. Then all I had to do was utilize that function in the custom formatting like I would anything else.

Votes

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
community guidelines
Community Expert ,
Jan 23, 2019 Jan 23, 2019

Copy link to clipboard

Copied

LATEST

Glad you got all the pieces together. The custom format script is often overlooked.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines