我坚持在 HTML 5 中格式化货币。我有一个应用程序,我必须在其中格式化货币。我有以下代码片段
<td class="right"><span th:inline="text">$ [[${abc.value}]]</span></td>
我从 DAO abc 读取货币值的位置,它应该被格式化。 当前打印 $ 1200000.0 它应该打印 $ 1,200,000.0 .0
最佳答案
您可以使用 #numbers
实用程序对象,您可以在此处查看哪些方法:http://www.thymeleaf.org/apidocs/thymeleaf/2.0.15/org/thymeleaf/expression/Numbers.html
例如:
<span th:inline="text">$ [[${#numbers.formatDecimal(abc.value, 0, 'COMMA', 2, 'POINT')}]]</span>
不过,您也可以在不进行内联的情况下执行此操作(这是 thymeleaf 推荐的方式):
<td>$ <span th:text="${#numbers.formatDecimal(abc.value, 0, 'COMMA', 2, 'POINT')}">10.00</span></td>
关于java - 如何使用 thymeleaf 格式化 HTML5 中的货币,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14160304/