在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 Action 类,它是 ArrayList
类Info
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)
中我不能使用${}
我可以访问 <% %>
中的那些变量吗?或者我可以使用 formatter .format()
在 <c:>
标签
最佳答案
使用 JSTL Format Number
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:formatNumber type="number" minFractionDigits="2" maxFractionDigits="2" value="${ info.totalDelay*100/info.totalShipment } " />
关于java - JSTL中计算的jsp中访问JSTL变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25591194/