Solved

Change the method from Float to BigDecimal

Posted on 2012-03-26
12
383 Views
Last Modified: 2012-03-30
Hello,

I am new to Java and would like to you show me how to change the following java method c from Float to BigDecimal.  There have been errors with the tTotalTC figures.  The line of code in questions is:  f = Float.valueOf (to.getTaskOrdCombinedCost ());

Thanks for your help.

CODE BEGINS
 // Task Orders
        f=0;
        Iterator<FsTaskOrd> toIterator = toCollection.iterator();
        while (toIterator.hasNext ()) {
            FsTaskOrd to = toIterator.next();
            if (to != null) {
                if (ctrNam == null) {
                    ctrNam = to.getCtrNam ();
                }
                f=0;
                if (to.getTaskOrdQty()!=null) {
                    f = Float.valueOf (to.getTaskOrdQty ());
                }
                tTotalQ = tTotalQ + f;
               
                f=0;
                if ((to.getTaskOrdCombinedCost ()) != null) {
                    f = Float.valueOf (to.getTaskOrdCombinedCost ());
                }
                tTotalTC = tTotalTC + f;
            }
        } // End of while
CODE ENDS
0
Comment
Question by:capturetheflag
[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
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 37765730
<<f=0>>

f is initialized to 0, but with 'what' data type?
0
 
LVL 1

Author Comment

by:capturetheflag
ID: 37765795
Hello,

Here are the data types.  Thanks

        //Task Ord Totals
        double tTotalQ = 0;
        double tTotalTC = 0;

        double f = 0;
        String strValue = "";
        String ctrNam = null;
0
 
LVL 1

Author Comment

by:capturetheflag
ID: 37765810
Hello,

I have also imported these packages.

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Collection;
import java.util.Iterator;

capturetheflag
0
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

 
LVL 86

Expert Comment

by:CEHJ
ID: 37765857
There have been errors with the tTotalTC figures.

I notice there are still String types there - make sure they're not used in calculations.
Have you completely changed the code as i instructed in your last question about decimal errors?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37766844
0
 
LVL 1

Author Comment

by:capturetheflag
ID: 37771193
Hello,
 I am having trouble with this line of code.  i do not know how to change the code.
The number is coming in correctly but is converted incorrectly with this line of code.
What is the syntax?  Thanks for your help.

f = Float.valueOf (to.getTaskOrdCombinedCost ());
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37771233
Please, try to make a small self-consistent snippet of code which we cna try to compile and execute ourspeves.
Otherwise we don't have your classes and your types - it is really difficult to naswer your question.
Make a small class and try to recreate your problem with BigDecimal to float conversion.
This class can even help you resolve this issue yourslef.
If not , we can help you, but the snippet you quoted above has custom types for which there is no definition, so it is very difficult to help you.
0
 
LVL 1

Author Comment

by:capturetheflag
ID: 37771415
Hello for_van,

thanks for your help.  I have attached the jave files that I think you made need to review the code. Please let me know if you need anything else.  thanks
FsInvoice.txt
FsTaskOrder.txt
FundingSummaryData.txt
GetFundingSummaryAction.txt
TaskOrderData.txt
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37771464
Please, read the title of your question:

"change the method for float to BigDecimal"

If this is the question of how to change method from float to BigDecimal - do  we really need your whole project to address the issue?
If you analyze the point where you are having troubles, abstract it from all other details of your code
and make a short class where this problem is concentrated - it will help you to understand yourslef where is really your prooblem and it will help us relieveiung us from the necessity of going through all that code.
That is also the basic approach to solving any problems in code and even beyond - just analyze your issue, come down to individual points and isolate the places where the problems need to be addressed. You cannot study the whole thing every  time.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 37771611
I've already told you what to do here:
http://www.experts-exchange.com/Programming/Languages/Java/Q_27644031.html#a37753329

    public String getTaskOrdCombinedCost () {
        return twoPlaces.format(this.taskOrdCombinedCost);
    }

Open in new window


should NOT return a String, but double:

 
public double getTaskOrdCombinedCost () {
        return taskOrdCombinedCost;
    }

Open in new window

0
 
LVL 1

Author Closing Comment

by:capturetheflag
ID: 37783594
Thanks,
for your help
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37787074
:)
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
runtime exception 2 67
Delete Android all or certain applications data programmatically 9 152
netbeans can not run self signed app 8 37
Java import explained 4 48
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

738 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