Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!

# Integer to double

Erre ced
Greenhorn
Posts: 3
Hi!
I have i small problem white my program.
I want my Integer to p� a double. I had tested:
double tal = (double) intal;
but it dosent work

thank U for helping
erre

Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
You don't have to cast.

double tal = intal;

That will work.

Erre ced
Greenhorn
Posts: 3
private Integer antalTim;
private double timLon;

public Integer getAntalTim()
{
return antalTim;
}

public void setAntalTim(Integer newAntalTim)
{
antalTim = newAntalTim;
}

public double getTimLon()
{
return timLon;
}

public void setTimLon(double newTimLon)
{
timLon = newTimLon;
}
public double anstalldlon()
{
double tal = getAntalTim();
return (tal * (this.getTimLon()));
}
so I got this mess:
Error(28,19): incompatible types; found: java.lang.Integer, required: double
I dont know if i was clear before when I written the first mess
thnks
erre

marc weber
Sheriff
Posts: 11343
If you mean "Integer" as an instance of the wrapper class, then you'll want to call the method doubleValue() to return a double.
[ September 29, 2004: Message edited by: marc weber ]

Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Ahh, didn't realize you were talking about Integer. Marc is correct.

Jeff Bosch
Ranch Hand
Posts: 805
There's a difference between Integer (a class) and an integer (a primitive type). To get the double value of an Integer, use the doubleValue() method on the Integer to get the result.

Integer i = new Integer( "5" );
double d = i.doubleValue();

Hope that helps.

somkiat puisungnoen
Ranch Hand
Posts: 1312
Originally posted by Erre ced:
Hi!
I have i small problem white my program.
I want my Integer to p� a double. I had tested:
double tal = (double) intal;
but it dosent work

thank U for helping
erre

Why do you want to cast Integer to Double ?

I think , it not make sense.

Because if you have 10 when you cast to double is 10.0 .