没有分数的价值

时间:2014-11-27 14:21:21

标签: jstl

如何打印没有分数的值?例如:

${bites/1024}

其中bites等于100000.输出为97,65625。我想改为打印97

1 个答案:

答案 0 :(得分:2)

您可以使用jstl format个数字执行此操作。

这是一个例子。

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<c:set var="bites" value="100000" />
<c:set var="result" value="${bites/1024}"/>
<fmt:formatNumber value="${result-(result%1)}" pattern="#"></fmt:formatNumber>

pattern="#" - remove decimal places,you can specify your own decimal places if you want.
n-(n%1) - equation result to floor value. 

jstl functions中的子字符串组合。

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>


<fmt:formatNumber value="${fn:substring(bites/1024, 0, 3)}" type="NUMBER"></fmt:formatNumber>