我找不到在Thymeleaf中获取十进制数的整个部分的方法。
例如:2,54将是2,或234,01将是234。
向上或向下舍入数字,但2,54到3而不是2。
答案 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>