• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 10280
  • Last Modified:

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...
0
Tension
Asked:
Tension
1 Solution
 
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
 
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
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:
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
 
siliconeagleCommented:
or just:-
public BigDecimal getAmount() {
    return amount.setScale(2);
}
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now