问题描述
我很难在HTML 5中格式化货币。我有应用程序,我必须格式化货币。我有以下代码段
I am stuck with formatting the currency in HTML 5. I have application where I have to format the currency. I have below code snippet
<td class="right"><span th:inline="text">$ [[${abc.value}]]</span></td>
从DAO abc我读取货币值时,应格式化。
目前打印$ 1200000.0应打印$ 1,200,000.0 .0
Where from DAO abc I am reading the currency value, it should be formatted. Currently printing $ 1200000.0 it should print $ 1,200,000.0 .0
推荐答案
您可以使用 #numbers
实用程序对象,您可以在此处看到哪些方法:
You can use the #numbers
utility object, which methods you can see here: 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>
尽管如此,你也可以在没有内联的情况下做到这一点(这是百里香推荐的方式):
Nevertheless, you can also do this without inlining (which is the thymeleaf recommended way):
<td>$ <span th:text="${#numbers.formatDecimal(abc.value, 0, 'COMMA', 2, 'POINT')}">10.00</span></td>
这篇关于如何使用thymeleaf格式化HTML5中的货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!