Html 根据其值类型,将条件放入Thymeleaf中

Html 根据其值类型,将条件放入Thymeleaf中,html,spring-mvc,thymeleaf,Html,Spring Mvc,Thymeleaf,我正在创建一个表,我想在其中输入值。通常它们是普通值,但很少需要显示其十进制值 <td th:each="dayWorked:${metier.getUserDayWorked(users)}"> [[${#numbers.formatDecimal(dayWorked,1,1)}]] </td> 我正在使用formatDecimal剪切所有十进制值 <td th:each="dayWorked:${metier.getUserDayWorked(us

我正在创建一个表,我想在其中输入值。通常它们是普通值,但很少需要显示其十进制值

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

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

</td>
我正在使用
formatDecimal
剪切所有十进制值

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

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

</td>

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

有没有办法在其中包含条件,只删除空十进制位,但让它们显示出来?

您可以尝试使用模数运算符,将您的
日工作
值除以
1
,并检查余数是否等于零:

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


我认为这是可能的,但不清楚您想要什么。您能提供一些示例值以及如何显示每个值吗?我希望当值为“20.0”时显示“20”,当值为“19.5”时显示“19.5”,因此,您的答案是正确的,您只需更改工作日的输出,如果为真,如下