2017-02-13 28 views
0

我沒有找到在Thymeleaf中獲得十進制數的整個部分的方法。如何提取Thymeleaf中的整數?

例如:2,54將是2,或234,01將234

numbers.formatInteger

回合數上升或下降,但2,54到達3而不是2

回答

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> 
+0

它的工作原理,但我不明白你爲什麼要牽扯控制器進入東西是表示層。爲什麼格式(n)單獨不起作用。非常感謝。 – Mike