How to handle negative values in pdf template

To ensure that the value in your FreeMarker template always displays as a positive number, you can use the abs (absolute) function provided by FreeMarker. Here’s how you can modify your code:

<td colspan="1" align="center">${(item.quantity - item.quantityavailable)?abs}</td>

Explanation:

  • ${item.quantity - item.quantityavailable} calculates the difference.
  • ?abs is a built-in FreeMarker function that converts a number to its absolute value, ensuring it is always positive.

This will ensure that even if the calculated difference is negative, it will display as a positive number in your Advanced PDF/HTML template.

Leave a comment

Your email address will not be published. Required fields are marked *