Skip to main content
LorianGans
Participating Frequently
December 15, 2023
Answered

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

  • December 15, 2023
  • 2 replies
  • 2562 views

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.

This topic has been closed for replies.
Correct answer try67

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!

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
December 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!

LorianGans
Participating Frequently
December 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!

try67
Community Expert
Community Expert
December 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!


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

 

 

Thom Parker
Community Expert
Community Expert
December 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 PDFScriptingUse the Acrobat JavaScript Reference early and often
LorianGans
Participating Frequently
December 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