Solved

double addition problem

Posted on 2002-07-01
2
253 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
  • 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java - sorting a list of objects where the properties of the objects can change during the sort 7 51
jar file executable 12 51
fibonacci ten numbers 4 38
by zero exception 10 40
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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:

776 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