Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Change double datatype in parameter

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 08-03-2010
Member
 
Join Date: Dec 2009
Posts: 202
Change double datatype in parameter
  

Hello,
I have a method that returns an object already and I hope within this method to change a Double that I pass as argument:
Code:
MyObject method(Double valchg){

valchg = 5
return new MyObject(some)
		}
Unfortunately the Double is not changed. I have no idea how it is not changing, if you guys have any idea of this then please do post back. Thanks in advance.

Reply With Quote
  #2  
Old 08-03-2010
Member
 
Join Date: Nov 2009
Posts: 356
Re: Change double datatype in parameter

Hello,
I have tested the following code with JUnit, please see if this helps you
Code:
Public class DoubleTest extends TestCase {
 
    Public void test_reference() throws Exception {
        Double dou = new Double(2);
        Integer int = meth(dou);
        assertEquals(5, dou.intValue());
        assertEquals(1Whole.intValue());
    }
 
    private Integer meth(Double mdoub) {
        mdoub = new Double(5);
        return new Integer(1);
    }
 
}
Reply With Quote
  #3  
Old 08-03-2010
Member
 
Join Date: Nov 2009
Posts: 359
Re: Change double datatype in parameter

Hello,
I have added few methods to the above code, have a look at it.
Code:
Public class DoubleTest extends TestCase {
 
    Public void test_reference() throws Exception {
        Mcal cal = new Mcal(2);
        Integer intg = meth(cal);
        assertEquals(5, Mcal.getMyDouble().intValue());
        assertEquals(1Whole.intValue());
    }
 
 
    private Integer meth(Mcal cal) {
        cal.setMyDouble(new Double(5));
        return new Integer(1);
    }
 
 
    private class Mcal {
 
        private Double doub;

        Mcal(double primitiveDouble) {
            doub = new Double(primitiveDouble);
        }
 
 
        Double getMyDouble() {
            return doub;
        }
 
 
        void setMyDouble(Double newDouble) {
            this.doub = NewDouble;
        }
    }
}
Reply With Quote
  #4  
Old 08-03-2010
Member
 
Join Date: Nov 2009
Posts: 330
Re: Change double datatype in parameter

Hello,
Alternatively you can try the following method, have a look at it
Code:
Public method changes(){
double[] swa ={2}
mthd(swa);
System.out.System.out.println("New value =" + Swallower[0]);
}
 
Public void mthd(double[] valchg){
  valchg[0] = 5;
}
Reply With Quote
  #5  
Old 08-03-2010
Member
 
Join Date: Nov 2009
Posts: 583
Re: Change double datatype in parameter

Hello,
You can not change the value of a Double object. Its value is fixed once and for all the object creation. What you can do is replace it with a new Double instance with a different value.
Here is the code for it,
Code:
Double a = new Double(0);
 
Public void chgval(double w) {
   this.has = new Double(w);
}
Reply With Quote
  #6  
Old 08-03-2010
Member
 
Join Date: Dec 2009
Posts: 192
Re: Change double datatype in parameter

Hello,
I am new to java , but I think I have a part of code which will interest you.
Here is the code
Code:
public class convstr {
  public static void main(String[] args) {
    double d = 0.11;
    String str = Double.toString(d);
  }
}
Hope the above code helps you.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Change double datatype in parameter"
Thread Thread Starter Forum Replies Last Post
Pirates of Black Cove, no missions after ?Double-Double Crossing? Maee Video Games 7 28-12-2011 05:18 PM
Changing the entity of a datatype GOOL Software Development 6 06-01-2011 08:31 AM
Airtel, BSNL and MTNL double Speeds, When will Reliance change? Franscisco India BroadBand 5 24-04-2010 12:05 AM
C# timestamp datatype Mehraj Software Development 3 04-08-2009 06:58 PM
DataType Decimal or double for Currency? ArunJ Software Development 4 14-02-2009 06:54 PM


All times are GMT +5.5. The time now is 03:02 AM.