Solved

Change the method from Float to BigDecimal

Posted on 2012-03-26
12
386 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

617 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