Odd to even rounding script

Community Beginner ,
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

136

Likes

Translate

Translate

Report

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

1 Correct Answer

Community Beginner , Jan 23, 2019
markt31311181 Community Beginner , 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.

Likes

Translate

Translate
Jump to answer Jump to answer
Adobe Community Professional ,
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?

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
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.

Likes

Translate

Translate

Report

Report
Reply
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 ,
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.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
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.

Likes

Translate

Translate

Report

Report
Reply
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 ,
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

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
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.

Likes

Translate

Translate

Report

Report
Reply
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 ,
Jan 23, 2019

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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