Formatting calculated values in Adobe Document Generation API

152 Views Asked by At

In the template language docs for Adobe Document Generation, mathematical expressions can be done using tags like below...

{{expr(revenue - expenditure)}}

This works and outputs a number, but is there any way to apply formatting to the number, for example, $50,000.00 where the calculated value is just 50000?

1

There are 1 best solutions below

0
On BEST ANSWER

Remember that doc gen uses JSONata (https://docs.jsonata.org/overview.html) for it's template parsing. As I've learned and played with docgen, the JSONata docs have been really helpful. For this particular example, there's a function built in documented under Numeric functions - $formatNumber. At minimum it takes a number input and a mask. So to format it as you would want, use:

{{$formatNumber(revenue-expenditure, '#,###.00')}}

Notice that you don't use expr above, just the function.