在 thymeleaf 中删除 formatCurrency() 中的货币符号

问题描述 投票:0回答:1

有了这个

 th:text="*{#numbers.formatCurrency(roomEntityList.get(0).price)}"

我的浏览器将在我的国家/地区显示

235.235 đ
。 我希望它显示
235.235

如何删除“đ”符号? 我已经查过了,但似乎我们对 html 中的 formatCurrency 能做的事情不多

html thymeleaf currency
1个回答
0
投票

我在文档中没有看到任何对此的本机支持,但实现它的一种方法是使用正则表达式:

<span
  th:with="originalPrice=${#numbers.formatCurrency(roomEntityList.get(0).price)}, 
           onlyNumbersAndDot=${#strings.replaceAll(originalPrice, '[^\\d.]+', '')}" 
  th:utext="${onlyNumbersAndDot}"
></span>

首先,

th:with
用于创建两个变量:

  • originalPrice
    保存格式化的货币值
  • onlyNumbersAndDot
    将正则表达式
    [^\\d.]+
    应用于
    originalPrice
    ,它匹配任何不需要的字符,因此
    replaceAll
    可以将它们替换为空字符串

然后

th:utext
用于显示修改后的价格,现在仅包含数字和点。

© www.soinside.com 2019 - 2024. All rights reserved.