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

Remove Trailing Zeros in a Decimal

New Here ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

I have Number fields in an Adobe Acrobat form that need to be able to be entered as either a whole number or a decimal. Easy enough. I also need up to two decimal places shown, also easy. However, I can't figure out a way to hide the trailing zeros in a decimal in order to "clean up" the look of it. For example:

I type          What appears          I want

8.25            8.25                         8.25

22.7            22.70                       22.7

3                 3.00                         3

 

Does anyone know how to do this?

 

Thanks,

TOPICS
PDF forms

Views

9.2K

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 , Mar 24, 2020 Mar 24, 2020

Custom format script

 

event.value = util.printf("%,02.2f",event.value).replace(/\.?0+$/,"");

Votes

Translate

Translate
Community Beginner ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

Thanks. It worked. I also added the same script to text4 and a script for rounding the final result. 

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 ,
Jun 05, 2021 Jun 05, 2021

Copy link to clipboard

Copied

Worked brilliantly. Thanks for all the help.

Just like to ask you one last thing.

Is it possible to create a script that blanks out all the fields ( making them invisible )  in the same row when no "Name" is inserted ?

 

Thanks

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 ,
Jun 06, 2021 Jun 06, 2021

Copy link to clipboard

Copied

this.getField("Text1").display = (event.value=="") ? display.hidden : display.visible;

 

If I place this script in the "Run Custom Validation Script" of the "Name field", then the "Text1" becomes invisible.

I have to click enter on the keyboard for it to work ( is that normal ? ).

But what if I want all the text fields ( exactly 9 ) in the row  to disappear at the same time ?

Thanks

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 ,
Jun 06, 2021 Jun 06, 2021

Copy link to clipboard

Copied

Is there also any kind of script that would make invisible all the fields of the same page ?

Thanks

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 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

LATEST

Yes,  However, this is a completely different topic than the forum thread. You should consider posting it to a new thread.

 

Just to provide some quick answers. 

1) The validation script is run after the user commits the data to the field, but before the data is actually commited, which is of course what validation is all about, checking the data before it is fully committed to the field. The user signals that they want the data committed by pressing enter or exiting the field. 

 

2)  There are a few different ways to write a script that hides/shows several fields at the same time. You'll find a more infomation here:

https://www.pdfscripting.com/public/Hiding-and-Showing-Form-Fields.cfm

 

  

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

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 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

You must round the calculated values.

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 01, 2021 Jun 01, 2021

Copy link to clipboard

Copied

The "invisible decimals" are the actual value of the fields, so that's what you will get when you export the form data. If you don't want that to happen then you need to change the actual value, not just format it, or use a script to perform the rounding on the values when you export them.

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