---el表达式保留两位小数、使用jstl <fmt:formatNumber>标签保留两位小数

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<fmt:formatNumber type="number" value="${688.87 * 0.8 }" pattern="0.00" maxFractionDigits="2"/>

<td><fmt:formatNumbertype="number"value="${item.lakecoin}"pattern="0.00" /></td>

<fmt:formatNumber type="number" value="${lb.monBzfj }" maxFractionDigits="2"/>这里的maxFractionDigits="2"是什么意思啊

max最大 fraction小数 digits位数
最多保留小数位数 = 2

---jsp页面判定某个变量为负值的时候显示为红色
<tdnowrap class="tdjj"align="center">
    <c:iftest="${list.profitmoney < '0'}">
        <fontcolor="red">${list.profitmoney}</font>
    </c:if>
    <c:iftest="${list.profitmoney >= '0'}">
        <fontcolor="black">${list.profitmoney}</font>
    </c:if>
</td>

${list.profitmoney}
是jsp页面查询出来的某个变量的值。

上面代码是为了实现如果为负值,字体颜色标红。如果为正值或者0,则字体颜色为黑。

<td>//if的方法
  <c:iftest="${item.anxcoin<0}">
        <fontcolor="red"><fmt:formatNumbertype="number"value="${item.anxcoin}"pattern="0.00" /></font>
  </c:if>
  <c:iftest="${item.anxcoin>=0}">
        <fmt:formatNumbertype="number"value="${item.anxcoin}"pattern="0.00" />
  </c:if>
</td>

choose  when otherwise 的方法

<td><c:choose>
    <c:whentest="${item.anxcoin<0}">
        <fontcolor="red"><fmt:formatNumbertype="number"value="${item.anxcoin}"pattern="0.00" /></font>
    </c:when>
    <c:otherwise><fmt:formatNumbertype="number"value="${item.anxcoin}"pattern="0.00" /></c:otherwise>
</c:choose></td>

标签: none

添加新评论