我被HTML5中的格式化货币卡住了。我有一个应用程序,我必须格式化货币。我有下面的代码片段
<td class="right"><span th:inline="text">$ [[${abc.value}]]</span></td>
当我从DAO abc读取货币值时,它应该格式化。当前打印$ 1200000.0应打印$ 1,200,000.0 .0
发布于 2013-01-05 06:15:29
您可以使用#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>
不过,您也可以在不使用内联的情况下完成此操作(这是胸腺叶推荐的方式):
<td>$ <span th:text="${#numbers.formatDecimal(abc.value, 0, 'COMMA', 2, 'POINT')}">10.00</span></td>
发布于 2018-02-05 15:20:41
现在,您可以更简单地在numbers
实用程序中调用formatCurrency
方法:
#numbers.formatCurrency(abc.value)
这也将消除对货币符号的需求。
示例:<span th:remove="tag" th:text="${#numbers.formatCurrency(abc.value)}">$100</span>
发布于 2018-12-13 04:54:05
您可以内联使用Thymeleaf的numbers实用程序对象,如下所示:
<span>[[${#numbers.formatCurrency(abc.value)}]]</span>
在视图中,它甚至会为您添加美元符号($)。
https://stackoverflow.com/questions/14160304
复制相似问题