Skip to main content
LorianGans
Participating Frequently
December 15, 2023
解決済み

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

  • December 15, 2023
  • 返信数 2.
  • 2613 ビュー

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.

このトピックへの返信は締め切られました。
解決に役立った回答 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

try67
Community Expert
try67Community Expert解決!
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
LorianGans作成者
Participating Frequently
December 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

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