jsp页面中格式化为小数点两位

时间:2022-05-29 15:03:42
      <td align="center">&nbsp;
<%
String avgnum = "";
if(request.getAttribute("avgnum") != null && !"".equals(request.getAttribute("avgnum"))){
double t = Double.parseDouble((String)request.getAttribute("avgnum"));
java.text.DecimalFormat df = new java.text.DecimalFormat("#.00");
avgnum = df.format(t);
}
%>
<%=avgnum %>
</td>