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...
TensionAsked:
Who is Participating?
 
siliconeagleCommented:
there is a method setScale on BigDecimal maybe the getter should return a BigDecimal with a different scale.
i.e.
public double getAmount() {
    return amount.setScale(2).doubleValue();
}
0
 
ldbkuttyCommented:
Try with:
<c:set var="totAmt" value="0.00"/>
0
 
MogalManicCommented:
Try initializing totAmt to 0.0.  Maybe JSTL is doing integer math.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
siliconeagleCommented:
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.
0
 
TensionAuthor Commented:
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
0
 
siliconeagleCommented:
or just:-
public BigDecimal getAmount() {
    return amount.setScale(2);
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.