java如何在Struts 2中格式化货币?
我在Struts中有以下代码
<fmt:formatNumber type="currency" currencySymbol="Rs" value="${product.priceSell + product.priceSell * rates[nr.count - 1]}" maxFractionDigits="2" minFractionDigits="2"/>
我想把它转换成Struts2。我尝试了下面的代码,但它不起作用
<s:text name="format.money">
<s:param name="value" value="%{#product.priceSell+ #product.priceSell * #rates[#nr.count - 1]}" />
</s:text>
注:费率为Arraylist<String>
# 1 楼答案
您可以在Struts2中使用JSTL
fmt
标记。jspel表达式搜索Struts2中的所有作用域和valueStack
。类似于OGNL的#attr
前缀。因此,要访问作用域变量并在所有作用域中搜索,您应该尝试以下操作注意,表达式中的值不应为
String
类型。如果将值保留为字符串,则需要在表达式中将其作为有效数字使用之前对其进行解析,这最好在操作中进行,而不是在JSP中