joelgeraci
joelgeraci

Reputation: 4917

Formatting calculated values in Adobe Document Generation API

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?

Upvotes: 1

Views: 191

Answers (1)

Raymond Camden
Raymond Camden

Reputation: 10857

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.

Upvotes: 2

Related Questions