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

Remove zero balances in calculated fields and keep two decimal points.

New Here ,
Mar 07, 2023 Mar 07, 2023

Copy link to clipboard

Copied

I have a fillable form with auto calculations for costs.  The blank calculation fields show up as 0.00 in the field.  I need the blanks to be empty showing no zeros.   When they do enter a number to calculate, I need the results to show 2 decimals, such as $ 19.50.  I prefer to do this using a custom format field.  Right now I have the follwing in my custom format scrip:

 

if((event.value == 0) || isNaN(event.value) || (event.value == Infinity))
event.value = "";

 

This shows 19.50 as 19.5 and shows 55.00 as 55.    How can I get this to display correctly?   

TOPICS
PDF forms

Views

646

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 ,
Mar 07, 2023 Mar 07, 2023

Copy link to clipboard

Copied

Add this to the end of your code:

else event.value = event.value.toFixed(2);

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 ,
Mar 07, 2023 Mar 07, 2023

Copy link to clipboard

Copied

LATEST

Or

if (event.value <= 0) event.value = "";
else event.value = util.printf("%0.2f",event.value);

 

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