Copy link to clipboard
Copied
I have a calculation that needs to return a currency value ($ symbol & two decimal places) if a field (A) used in the calculation is filled in (ie: showing a number value) then the Result field must show $x,xxx.xx.
(Currency + comma separator + two decimal places)
My calculation is set to be blank when field (A) is blank. I can't set the format for my result field to currency as it returns an error when Field (A) is changed from a value to blank.
What is the javascript to set this up and is it entered into the custom format script block?
Thanks
Copy link to clipboard
Copied
Opps should have not forced it to a string
event.value = ((event.value==0) || isNaN(event.value))?"": util.printf("$%,0.2f",event.value);
Just to be sure though. Before making this update. Remove all formatting from the field.
What appears in the result field when A is blank? The script will only show a blank if the actual calculated field value is either a 0 or something that is not a number.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Put this code in the custom format script.
event.value = ((event.valueAsString=="") || isNaN(event.value))?"": util.printf("$%,0.2f",event.value);
Here's an old article on formatting
https://acrobatusers.com/tutorials/formatting_text_fields/
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thanks - however, this shows $0.00 when Field (A) value is blank and I want it to be a blank field.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The problem is that the calculation is setting the field value to zero. Here's an easy solution.
event.value = ((event.valueAsString==0) || isNaN(event.value))?"": util.printf("$%,0.2f",event.value);
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Hi Thom
Thanks, but that doesn't work either - still shows the $0.00
Copy link to clipboard
Copied
Opps should have not forced it to a string
event.value = ((event.value==0) || isNaN(event.value))?"": util.printf("$%,0.2f",event.value);
Just to be sure though. Before making this update. Remove all formatting from the field.
What appears in the result field when A is blank? The script will only show a blank if the actual calculated field value is either a 0 or something that is not a number.
Use the Acrobat JavaScript Reference early and often

