Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Adding 2 numbers using jstl 1.0

Posted on 2004-10-31
8
Medium Priority
?
10,118 Views
Last Modified: 2013-11-24
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
Comment
Question by:Tension
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 32

Expert Comment

by:ldbkutty
ID: 12456494
Try with:
<c:set var="totAmt" value="0.00"/>
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 12456499
Try initializing totAmt to 0.0.  Maybe JSTL is doing integer math.
0
 
LVL 2

Expert Comment

by:siliconeagle
ID: 12461609
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Tension
ID: 12463685
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
 
LVL 2

Accepted Solution

by:
siliconeagle earned 300 total points
ID: 12481585
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
 
LVL 2

Expert Comment

by:siliconeagle
ID: 12481593
or just:-
public BigDecimal getAmount() {
    return amount.setScale(2);
}
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question