如何使用thymeleaf格式化HTML5中的货币 [英] How to format the currency in HTML5 with thymeleaf

查看:1233
本文介绍了如何使用thymeleaf格式化HTML5中的货币的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难在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 实用程序对象,您可以在此处看到哪些方法: http://www.thymeleaf.org/apidocs/thymeleaf/2.0.15/org/thymeleaf/expression/Numbers.html

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中的货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆