Skip to main content
npGar
Participant
May 7, 2026
Question

Remove Trailing Zeros in a Decimal from a Calculation

  • May 7, 2026
  • 3 replies
  • 96 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.

    3 replies

    PDF Automation Station
    Community Expert
    Community Expert
    May 11, 2026

    The script provided is a custom format script.

    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)
    npGar
    npGarAuthor
    Participant
    May 8, 2026

    The value is for a percentage and the stakeholder had an aesthetic request as opposed to an accurate one.

    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
    npGar
    npGarAuthor
    Participant
    May 8, 2026

    It didn’t seem to work. There may be a conflict in the snippet of code I already had. I needed to already force decimal values to round up. Here’s what I have. Trying to remove at trailing zero only in the GP% field. Thank you Thom.

    var usppu = this.getField("usppu").value; var usdcost = this.getField("usdcost").value; if (Number(usppu) > 0) { event.value = Math.ceil((Number(usppu) / Number(usdcost)) * 1000)/10; } else { event.value = ""; }

     

     

    Thom Parker
    Community Expert
    Community Expert
    May 8, 2026

    You cannot have two scripts operating on the same field. Remove all other scripts. Use only the formatting script I provided. 

     

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