Tension
asked on
Adding 2 numbers using jstl 1.0
Hi All,
I have an property "Amount" of type BigDecimal in my value object, the VO is put into an ArrayList and kept in an Session object.
<c:set var="totAmt" value="0"/>
<c:forEach items"..." var="X">
// Adding the Amount inside the loop
<c:set var="totAmt" value="${totAmt + X.Amount}"/>
</c:ForEach>
<c:out value="totAmt"/>
When I print out the result, it displays only the integer whole numbers of the value.
Ex:
123.45 [Actual Amount Value]
123 [Displays]
Thanks in advance...
I have an property "Amount" of type BigDecimal in my value object, the VO is put into an ArrayList and kept in an Session object.
<c:set var="totAmt" value="0"/>
<c:forEach items"..." var="X">
// Adding the Amount inside the loop
<c:set var="totAmt" value="${totAmt + X.Amount}"/>
</c:ForEach>
<c:out value="totAmt"/>
When I print out the result, it displays only the integer whole numbers of the value.
Ex:
123.45 [Actual Amount Value]
123 [Displays]
Thanks in advance...
Try initializing totAmt to 0.0. Maybe JSTL is doing integer math.
What type does X.getAmount() return int or float (or long or double). as long as there is a float there then JST should do floating point math. Check that X.getAmount() isn;t doing a round or otherwise converting to an integer.
ASKER
Hi,
I've tried initializing with
<c:set var="totAmt" value="0.00"/>
still it doen't work out.
X.getAmount() is of type BigDecimal
I've tried initializing with
<c:set var="totAmt" value="0.00"/>
still it doen't work out.
X.getAmount() is of type BigDecimal
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or just:-
public BigDecimal getAmount() {
return amount.setScale(2);
}
public BigDecimal getAmount() {
return amount.setScale(2);
}
<c:set var="totAmt" value="0.00"/>