Solved

double addition problem

Posted on 2002-07-01
2
257 Views
Last Modified: 2008-02-26
Could someone please tell me what might be wrong.  When I display the grand total I get lots of zero's that I don't want.  

//global
double _totalBalance              = 0.0;

//method scope
double paymentAmount           = 0.00;
double pendingPaymentTotal       = 0.00;

//retrieve from db
paymentAmount = rs.getDouble("Amount_Paid");
pendingPaymentTotal += paymentAmount;

//get the total balance
_totalBalance += pendingPaymentTotal;

//This shows the correct balance
These are the two balances that make up the one below that is message up:
Ex. 25196.67
Ex. 30627.23
sb.append("<td><b>" + String.valueOf(pendingPaymentTotal) + "</b></td>");

//This show lots of zero's that should not be visible.
Ex. 55823.899999999994
agScriptHelper.alert(String.valueOf(_totalBalance));
0
Comment
Question by:CSharpRules
[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
  • 2
2 Comments
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 7123309
You need to use DecimalFormat to control the number of decimal places displayed:

DecimalFormat fmt = new DecimalFormat("#.##");
agScriptHelper.alert(fmt.format(_totalBalance));
0
 
LVL 92

Expert Comment

by:objects
ID: 7125466
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Maven Project: Hibernate Dependencies Conflict 10 95
ejb mdb examples 1 39
Eclipse for Java EE development 2 68
wild fly 8 startup error 2 82
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

752 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