如何在Thymeleaf中提取整数?

时间:2017-02-13 15:43:22

标签: thymeleaf

我找不到在Thymeleaf中获取十进制数的整个部分的方法。

例如:2,54将是2,或234,01将是234。

numbers.formatInteger

向上或向下舍入数字,但2,54到3而不是2。

1 个答案:

答案 0 :(得分:0)

我无法通过内置的百万美元对象/方法找到一种简单的方法,但这会起作用(即使它有点痛苦)。

控制器

@GetMapping
public String page(Map<String, Object> model) {
    .
    .
    DecimalFormat f = new DecimalFormat("#");
    f.setRoundingMode(RoundingMode.FLOOR);
    model.put("format", f);
    .
    .
}

<th:block th:with="n=${2.54}">
    <!-- outputs 2 -->
    <span th:text="${format.format(n)}" />
</th:block>