• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Integer to double

 
Erre ced
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have to cast.

double tal = intal;

That will work.
 
Erre ced
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh, didn't realize you were talking about Integer. Marc is correct.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic