【发布时间】:2014-08-31 10:44:44
【问题描述】:
在jsp中我有这部分并且工作正常
<c:forEach var="info" items="${infoList}" >
<tr>
<td>${info.key} </td>
<td>${info.total}</td>
<td>${info.delay}</td>
</tr>
</c:forEach>
这里的infoList 来自struts 动作类,它是Info 类的ArrayList
public class Info{
private String key;
private String total;
private String delay
}
现在我需要添加另一个<td>,它将打印计算出的百分比,如 ${info.delay}*100/${info.total},但将精确打印小数点后两位数。
我试过了
${ info.totalDelay*100/info.totalShipment }
打印百分比但不能限制为 2 位数。在java中我可以使用
NumberFormat formatter = new DecimalFormat("#0.00");
但是我将如何做到这一点,因为在<% %> (jap tag) 我不能使用${}
我可以如何访问<% %> 中的那些变量吗?或者我可以在<c:> 标签中使用formatter .format() 吗
【问题讨论】: