Skip to main content
T-mim
Participant
March 24, 2020
Answered

Remove Trailing Zeros in a Decimal

  • March 24, 2020
  • 2 replies
  • 15779 views

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,

This topic has been closed for replies.
Correct answer Thom Parker

Custom format script

 

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

2 replies

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
March 24, 2020

Custom format script

 

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

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
May 30, 2021

Thanks. Exactly what I needed.

Is there any way to remove just the trailing double zeros and not all of them ?

For example 

9.57    remains    9.57

9.50    remains    9.50

9.00   becomes    9

 

Thanks

try67
Community Expert
Community Expert
May 30, 2021

Change the last bit of the code Thom provided to:

 

replace(/\.?0{2,}$/,"");


PS. I think there's a mistake in that code. I would remove the question mark after the dot. If you don't it will also convert "2500" to "25"...

try67
Community Expert
Community Expert
March 24, 2020

You can't do that with the built-in Number format setting. You'll need to write your own Format script.