Solved

Change the method from Float to BigDecimal

Posted on 2012-03-26
12
366 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
  • 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

744 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

12 Experts available now in Live!

Get 1:1 Help Now