Answer the question
In order to leave comments, you need to log in
How to round number in jsp?
How to round number in jsp??
I divide one number by another and I got a non-round one, is it possible to make it a round number?
${rezult.a/rezult.b}
Sending an object to jsp. With jsp
Answer the question
In order to leave comments, you need to log in
I was puzzled by this question at one time and for myself I found such a solution
<c:set var="rezult.a" value="4"/>
<c:set var="rezult.b" value="10"/>
<%
Float result_A = Float.valueOf("" + pageContext.getAttribute("rezult.a", PageContext.PAGE_SCOPE));
Float result_B = Float.valueOf("" + pageContext.getAttribute("rezult.b", PageContext.PAGE_SCOPE));
MathContext myMathContext = new MathContext(15, RoundingMode.HALF_UP);
BigDecimal bd;
bd = new BigDecimal((float)result_A/result_B, myMathContext);
BigDecimal bdRounded = bd.setScale(2, RoundingMode.HALF_UP);
pageContext.getSession().setAttribute("RESULT", bdRounded.floatValue());
%>
<br>
RESULT: ${RESULT}
RESULT: 0.4
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question