shas
shas

Reputation: 418

Put Condition in Thymeleaf, Depending on its Value Type

I am creating a table where I want to put value. Usually they are plain value, but few of them need to be displayed with their decimal value

I am using formatDecimal to cut all decimal value

<td th:each="dayWorked:${metier.getUserDayWorked(users)}">

    [[${#numbers.formatDecimal(dayWorked,1,1)}]]

</td>

Is there any way to include condition in it to only remove null decimal bit, but let those have be displayed?

Upvotes: 1

Views: 1179

Answers (1)

DimaSan
DimaSan

Reputation: 12684

You could try to use modulus operator and divide your dayWorked value by 1 and check whether the remainder equals zero:

<span th:text="${dayWorked} % 1 == 0 
                    ? ${#numbers.formatDecimal(dayWorked,1,0)}
                    : ${#numbers.formatDecimal(dayWorked,1,1)}"/>

Upvotes: 2

Related Questions