Home arrow static arrow Java Programming [Archive] - Double double problems...
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Double double problems...
This topic has 4 replies on 1 page.

Posts:12
Registered: 6/21/04
Double double problems...  
Jun 25, 2004 11:11 AM



 
Ok, I want to do simple opperations with my Double values, I want to be able to divide two Double variables:
Double temp1, temp2, result;               for(int k = 0; k < Array2.length; k++) {                temp1 = Array1[k];                temp2 = Array2[k];                                if(temp1.compareTo(temp2) < 0) {                    result+=(temp1/temp2);  // <----where i get this error "operator / cannot be applied to java.lang.Double,java.lang.Double"                 }                sum++;            } 
 

Posts:24,036
Registered: 2/3/03
Re: Double double problems...  
Jun 25, 2004 11:14 AM (reply 1 of 4)



 
You can't divide or add Double objects. Use the corresponding primitive double values instead.
 

Posts:12
Registered: 6/21/04
Re: Double double problems...  
Jun 25, 2004 11:16 AM (reply 2 of 4)



 
If I can't do that then how do I convert my Double Array so that I can read it into a normal double temp1?
Suggestions?
    double temp1, temp2, result;    Double[] Array1, Array2; <- this has to be Double.                 // How can I convert the Array Double so I can read it to double then.                temp1 = Array1[k];                temp2 = Array2[k];
 

Posts:3,055
Registered: 18/06/98
Re: Double double problems...  
Jun 25, 2004 11:30 AM (reply 3 of 4)



 
Javadoc is your friend. See the javadoc of java.lang.Double

doubleValue
public double doubleValue()
Returns the double value of this Double object.
 

Posts:2,206
Registered: 8/15/02
Re: Double double problems...  
Jun 25, 2004 11:31 AM (reply 4 of 4)



 
result = new Double (result.doubleValue() + ( temp1.doubleValue()/temp2.doubleValue() ) ); 
 
This topic has 4 replies on 1 page.