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

Remove Trailing Zeros in a Decimal

  • March 24, 2020
  • 2 replies
  • 15777 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
T-mim
T-mimAuthor
Participant
March 24, 2020

Beautiful! That did it. Thanks Thom!

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.