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

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

New Here ,
Mar 07, 2023 Mar 07, 2023

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
1.0K
Translate
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

Add this to the end of your code:

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

Translate
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
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

Translate
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