Skip to main content
Participant
March 7, 2023
Question

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

  • March 7, 2023
  • 1 reply
  • 977 views

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?   

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
March 7, 2023

Add this to the end of your code:

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

Thom Parker
Community Expert
Community Expert
March 8, 2023

Or

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

 

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