How to convert value from double to Integer in jsp

2020-04-19 07:01发布

Supposing that In the jsp file, I want to show the value which is computed as below :

<c:when test="${userProduct.term.label == 'tháng'}">
                                <c:if test="${userProduct.term.value %12==0}"> ${userProduct.term.value/12} năm</c:if>

Supposing that value = 36 and the number which I want to show to user is 3. However, the number which I received is 3.0. Currently, I am looking for a way to show as I expected. Please tell me know the way to do it. Thanks.

标签: jsp
2条回答
叛逆
2楼-- · 2020-04-19 07:18

You can use the fmt:parseNumber tag

<c:set var="yourValue" value="${userProduct.term.value/12}" />
<fmt:parseNumber var="intValue" integerOnly="true" 
                       type="number" value="${yourValue}" />

http://www.tutorialspoint.com/jsp/jstl_format_parsenumber_tag.htm

查看更多
够拽才男人
3楼-- · 2020-04-19 07:36

You could use JSTL to accomplish this, specifically the <fmt:formatNumber> tag.

<c:if test="${userProduct.term.value %12==0}">
    <fmt:formatNumber value="${userProduct.term.value/12}"
                      maxFractionDigits="0" />
    năm
</c:if>
查看更多
登录 后发表回答