Solved

double addition problem

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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 95
Oracle SQL syntax check  without executing 6 98
Glassfish admin console not working 1 53
Eclipse Java import and method not resolved 4 73
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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…

679 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