在 Thymeleaf 中,如果存在零,是否有任何方法可以打印没有尾随零的货币?
例如:
49.20 美元 --> 49.20 美元
和
49.00 美元 --> 49 美元
我的想象是这样的:#numbers.formatCurrency(abc.value, removeTrailingZeros)
最佳答案
这是一种方法:
$<span th:text="${#numbers.formatDecimal(value, 0, T(Math).round(value) == value ? 0 : 2)}" />
(我可能更愿意为此添加一个 getter,或某种实用方法。)
--
这个解决方案怎么样,如果你仍然只想使用 formatCurrency
:
${#strings.replace(#numbers.formatCurrency(abc.value), '.00', '')}
关于thymeleaf - 删除货币尾随零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52066661/