Solved

Change the method from Float to BigDecimal

Posted on 2012-03-26
12
376 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
diffSum example 4 37
factorial example 4 40
arguments to jar 5 26
Tomcat: Unable to run tomcat service. 2 20
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

803 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