aspose file tools*
The moose likes Beginning Java and the fly likes Integer to double Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Integer to double" Watch "Integer to double" New topic
Author

Integer to double

Erre ced
Greenhorn

Joined: Sep 29, 2004
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

Joined: Jul 11, 2001
Posts: 15286
    
    6

You don't have to cast.

double tal = intal;

That will work.


GenRocket - A Test Data Generation Platform
Erre ced
Greenhorn

Joined: Sep 29, 2004
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

Joined: Aug 31, 2004
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 ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Ahh, didn't realize you were talking about Integer. Marc is correct.
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
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.


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
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 .


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Integer to double
 
Similar Threads
I want to evalutate the cents field.
meaning of double angle brackets(<< >>) in Generics?
If Pkey of EB is of primitive type then what's the return type of ejbCreate()
problem about constructing Integer objects
Nested Map