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

Prevent rounding in number fields

Community Beginner ,
May 17, 2021 May 17, 2021

Copy link to clipboard

Copied

Hello to all,

using Acrobat Pro 2017 (Classic Release), I created a fillable form. In the form I have a column with number fields that have the following field properties according to the screenshots:

adobe_form_01.png

 

adobe_form_02.png

 

As expected, the form contains a 0.

However, numbers with commas can still be entered. In the PDF form, these numbers are then rounded, e.g. 1.99 becomes 2 (compare screenshots):

adobe_form_03a.png

 

adobe_form_03b.png

 

How can I prevent rounding in Acrobat Pro or prevent commas from being entered in the field?

I am already very grateful for tips, ideas and possibly code examples!

I probably won't be able to get around JavaScript.

Regards, Daniel Schunk

TOPICS
PDF forms

Views

2.9K

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 Expert , May 17, 2021 May 17, 2021

The entered values are not actually rounded, they are only formatted in a way that hides the decimal digits, because of the Number format you've selected. If you click the field after exiting it, you'll see that the value you entered is still there. Also, if you use it in a calculation it will use the entered value, not the displayed one.

So how to prevent the user from entering those decimals? You can't do it with the Number setting under Format, but you can by setting your own Keystroke script

...

Votes

Translate

Translate
Community Expert ,
May 17, 2021 May 17, 2021

Copy link to clipboard

Copied

The entered values are not actually rounded, they are only formatted in a way that hides the decimal digits, because of the Number format you've selected. If you click the field after exiting it, you'll see that the value you entered is still there. Also, if you use it in a calculation it will use the entered value, not the displayed one.

So how to prevent the user from entering those decimals? You can't do it with the Number setting under Format, but you can by setting your own Keystroke script (under Properties - Format - Custom). For example, you can use this one:

event.rc = /^\d*$/.test(event.change);

It will only allow the user to enter digits into the field.

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 ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

Hello, try67,

thank you very much for the quick help.

It worked with the code line

event.rc = /^\d*$/.test(event.change);

 

However, I had first put it in the "Custom formatting script" section. That was not correct.

It only works in the "Custom key input script" section, I found.

 

More generally, I must note that the documentation on JavaScript in PDF at Adobe is quite large, but not as immediately obvious as at Microsoft, for example.

 

Best regards,

Daniel

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 ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

I wrote it needs to go under the Custom Keystroke Script...

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
New Here ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

This is great - I had the same problem.  Is there a way to adjust this to allow input of negative numbers?

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 ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

Sure. Change it to this:

 

event.rc = /^-?\d*$/.test(event.change);

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
New Here ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

Awesome!!!  Thank you for the help (and so quickly!).   

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
Explorer ,
Sep 06, 2022 Sep 06, 2022

Copy link to clipboard

Copied

quote

The entered values are not actually rounded, they are only formatted in a way that hides the decimal digits, because of the Number format you've selected. If you click the field after exiting it, you'll see that the value you entered is still there. Also, if you use it in a calculation it will use the entered value, not the displayed one.

So how to prevent the user from entering those decimals? You can't do it with the Number setting under Format, but you can by setting your own Keystroke script (under Properties - Format - Custom). For example, you can use this one:

event.rc = /^\d*$/.test(event.change);

It will only allow the user to enter digits into the field.


By @try67

Is it posible to use displayed number in calculation? If it is how?

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
Explorer ,
Jun 30, 2023 Jun 30, 2023

Copy link to clipboard

Copied

Hello @try67 ,

 

I hope you don't mind me jumping in this thread, but this is the script I was looking for! Do you know how I can use this code but with a comma instead of a period for French decimal format?

 

And also, how do I display the characters showing decimals? It is now only showing a single digit, rather than a whole number + 2 decimals.

 

Your help is greatly appreciated!

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 ,
Jun 30, 2023 Jun 30, 2023

Copy link to clipboard

Copied

The whole point of this thread was to prevent the user from entering decimals... If you want to allow that (no matter in what format) then just use the built-in Number option, and then select the pattern you want it to have.

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 16, 2024 Jan 16, 2024

Copy link to clipboard

Copied

How do I use a script with the below?

I need for 2 decimals places to show with no rounding. 

EX: the total is 73.449, right now it's rounding to 73.45. I want it just to show 73.44. 

 

 

 

// Get first field value

var v1 = getField("Payroll6").value;


// Get second field value

var v2 = getField("Payroll7").value;


// Set this field value equal to the difference

event.value = (v1 * v2);

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 16, 2024 Jan 16, 2024

Copy link to clipboard

Copied

That is rounding, just down. You can do it using this code:

 

event.value = roundDown(v1 * v2, 2)

function roundDown(v, nDecimals) {
	return Math.floor(v * Math.pow(10, nDecimals)) / Math.pow(10, nDecimals);
}

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 ,
Feb 27, 2024 Feb 27, 2024

Copy link to clipboard

Copied

LATEST

Thank you so much, this worked perfectly.



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