thymeleaf - 删除货币尾随零

标签 thymeleaf

在 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/

相关文章:

spring-mvc - 秒 :authorize doesn't work

java - 使用 AJAX 与 Spring 和 Thymeleaf 发送字符串的正确方法是什么?状态 : 400

javascript - 如何使用 thymeleaf 获取文本区域数据

spring - Thymeleaf 中的过滤整数列表

java - 我需要使用 Thymeleaf 为我的 SPRING 应用程序创建绝对 URL

thymeleaf - 如何在 Thymeleaf 模板中添加不包含在生成的 HTML 中的源代码注释?

javascript - 如何使用 jQuery/JS 将下拉项设置为选中状态?

java - 使用 Thymeleaf 的 Sprint MVC App 无法使用标准 href 找到 CSS?

spring-mvc - 如何对使用 thymeleaf 的安全 Controller 进行单元测试(不获取 TemplateProcessingException)?

java - 使用 Thymeleaf 显示净化后的 HTML 的最干净方式?