删除货币的尾随零

vph*_*nyc 1 thymeleaf

在 Thymeleaf 中,如果存在零,有没有办法打印没有尾随零的货币?

例如:

49.20 美元 --> 49.20 美元

49.00 美元 --> 49 美元

我会想象的是这样的: #numbers.formatCurrency(abc.value, removeTrailingZeros)

Met*_*ids 6

这是一种方法:

$<span th:text="${#numbers.formatDecimal(value, 0, T(Math).round(value) == value ? 0 : 2)}" />
Run Code Online (Sandbox Code Playgroud)

(我可能更喜欢为此添加一个吸气剂,或某种实用方法。)

——

这个解决方案怎么样,如果你仍然只想使用formatCurrency

${#strings.replace(#numbers.formatCurrency(abc.value), '.00', '')}
Run Code Online (Sandbox Code Playgroud)