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

How to format a number field with the last 2 numbers as the decimals, not zeroes

Community Beginner ,
Dec 15, 2023 Dec 15, 2023

I've created several fillable PDFs for online use and I have set the number fields with 2 decimals but it automatically puts zeroes after the decimal. Is there a way to have it put the decimal before the last 2 numbers the user typed? 

 

So instead of:

- user types: 123456

- returns 123456.00

 

We want this:

- user types: 123456

- returns 1234.56

 

Is this possible? Thank you.

TOPICS
Create PDFs , Edit and convert PDFs , How to , PDF , PDF forms
1.8K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Dec 15, 2023 Dec 15, 2023

To do that you would need to divide the value by 100. You can use this code as the field's custom Validation script:

if (event.value) event.value/=100;

Note that this changes the actual value entered by the user, not just how it is displayed!

View solution in original post

Translate
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 ,
Dec 15, 2023 Dec 15, 2023

Yes, but it requires a custom keystroke script, it could also be done with a custom validation.

What you are asking for is not formatting. Formatting is about managing how a value is presented to the user. You are asking to change the entered value. This type of script will not work if the PDF is opened in a browser or mobile app that is not the Adobe Mobile Reader. If this is a problem, then you might want to rethink the process. 

 

 

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

Translate
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 ,
Dec 15, 2023 Dec 15, 2023

Thanks very much, Thom -

Your comment about it not working if the form is opened in a browser or mobile app is especially helpful as well. We were trying to help our users avoid having to enter decimals, thereby (hopefully) reducing the chance of keystroke errors. We'll just have to change our process a bit. 

Thanks again -

- Lorian

Translate
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 ,
Dec 15, 2023 Dec 15, 2023

To do that you would need to divide the value by 100. You can use this code as the field's custom Validation script:

if (event.value) event.value/=100;

Note that this changes the actual value entered by the user, not just how it is displayed!

Translate
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 ,
Dec 15, 2023 Dec 15, 2023

Thanks very much!! I tried it and it works beautifully! 

Now we just need to decide if that's the way we want to go, since both options have their pros and cons. If we're instructing the user that the system will automagically insert a decimal before the last 2 numbers they type, then it will allow them to just use the number keys, which might be simpler. Many are not super computer-literate. 

Thanks again to you both!

- Lorian

Translate
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 ,
Dec 15, 2023 Dec 15, 2023

One more question on this - if the last digit is a zero, the output is being calculated correctly but it's not displaying the zero at the end, so it looks like it's just giving 1 decimal place. 

 

For example, if the user enters 123456, it's correctly reflecting 1234.56.

BUT if they enter 543210, it's reflecting 5432.1

 

Is there a way to set it so it will include the zero at the end, so it would be 5432.10?

I realize they're the numericaly and financially the same, but they're visually jarring and just look sloppy, and also will likely cause doubt for our users as to whether it's working correctly.

Thank you!

Translate
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 ,
Dec 15, 2023 Dec 15, 2023

I tried it and the last zero was kept in tact. Did you set the field's Format to Number with 2 decimals?

Translate
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 ,
Dec 15, 2023 Dec 15, 2023

No - I had set it to Custom so I could use the script, but now I see I can (and apparently should) do that on the Validation tab.
Thanks!!

One (hopefully) final thing - I'm not able to multi-select the fields to which I want to apply this formatting, so I have to set them each individually, which just takes a long time. Any trick to that or is it a glitch in the app? I can set other attributes on multiple fields at once...

Thanks again!

Translate
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 ,
Dec 15, 2023 Dec 15, 2023

No, there's no trick. You can't apply a Format setting (or any other action, for that matter) en masse via Acrobat's UI. It can only be done using a script, like this (paid-for) tool I've developed:

https://www.try67.com/tool/acrobat-mass-edit-fields-actions

 

 

Translate
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 ,
Dec 15, 2023 Dec 15, 2023
LATEST

OK - thanks very much.

Translate
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