Link to home
Start Free TrialLog in
Avatar of Tension
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...
Avatar of ldbkutty
ldbkutty
Flag of India image

Try with:
<c:set var="totAmt" value="0.00"/>
Try initializing totAmt to 0.0.  Maybe JSTL is doing integer math.
Avatar of siliconeagle
siliconeagle

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.
Avatar of Tension

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
ASKER CERTIFIED SOLUTION
Avatar of siliconeagle
siliconeagle

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or just:-
public BigDecimal getAmount() {
    return amount.setScale(2);
}