Skip to main content
npGar
Participant
May 7, 2026
Question

Remove Trailing Zeros in a Decimal from a Calculation

  • May 7, 2026
  • 2 replies
  • 13 views

I have Number field in an Adobe Acrobat form that is a calculation of other entered number fields. In the Format tab, the decimal is set to one (1) decimal point (ie 27.5, 11.6, etc.). However, I’m wondering how to write a code to remove the ‘.#’ from the number value only when the decimal displays ‘.0’

Example:

236.0 should be  listed as only 236

Since the value is always going to be different when the equation triggers, I can’t write to a specific variable. Thank you for your help.

    2 replies

    Dave Creamer of IDEAS
    Community Expert
    Community Expert
    May 8, 2026

    Are these numbers scientific? If so, the .0 implies a level of accuracy. 

    David Creamer: Community Expert (ACI and ACE 1995-2023)
    Thom Parker
    Community Expert
    Community Expert
    May 7, 2026

    Here’s a format script. 

     

    if(Number.isInteger(event.value))
      event.value = util.printf("%d",event.value);
    else
      event.value = util.printf("%0.1f",event.value);

     

     

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