Solved

double addition problem

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
where is session ID cache stored 1 39
wordcount challenge 11 74
firstChar challenge 13 83
Groovy:unable to resolve class error 2 28
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now