删除货币的尾随零 [英] Remove trailing zeros on currency
本文介绍了删除货币的尾随零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Thymeleaf 中,如果存在零,有没有办法打印没有尾随零的货币?
In Thymeleaf, is there any way to print currencies without trailing zeroes if zeroes exist?
例如:
49.20 美元 --> 49.20 美元
$49.20 --> $49.20
和
49.00 美元 --> 49 美元
$49.00 --> $49
我的想象是这样的:#numbers.formatCurrency(abc.value, removeTrailingZeros)
推荐答案
这是一种方法:
$<span th:text="${#numbers.formatDecimal(value, 0, T(Math).round(value) == value ? 0 : 2)}" />
(我可能更喜欢为此添加一个 getter,或者某种实用方法.)
(I'd probably prefer adding a getter for this, or some kind of utility method.)
--
这个方案怎么样,如果你还是只想用formatCurrency
:
How about this solution, if you still only want to use formatCurrency
:
${#strings.replace(#numbers.formatCurrency(abc.value), '.00', '')}
这篇关于删除货币的尾随零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文