Search code examples
cssthymeleaf

How can I format a positive/negative number with th:class?


If I have a BigDecimal, is it possible to easily format it with a CSS class based on whether it's positive or negative?

Like:

th:class="${#numbers.isPositive(myBigDecimal) ? 'text-danger' : 'text-success'}"


Solution

  • Seems like the best workaround is:

    th:class="${myBigDecimal != null && myBigDecimal > 0 ? 'text-danger' : 'text-success'}"