Java - how to convert "Double" to "Integer"

I have a variable of type "Double" (not "double") and I need to convert it to "Integer" (not "int").  Can someone tell me how to do this?

I have tried:

(Integer)MyDouble  and I just get "Cannot cast from Double to Integer".

Also tried:

(int)MyDouble and got a similar error.

Please help.
jbaird123Asked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
Oops
Integer i = new Integer((int)d.doubleValue());

Open in new window

0
 
CEHJCommented:
Try
Integer i = new Integer((int).d.doubleValue());

Open in new window

0
 
jbaird123Author Commented:
That worked perfectly.  Thank you!

Do you know of any good websites with this sort of information easily accessible?  I need it from time to time and Googling this often just frustrates me.
0
 
CEHJCommented:
That kind of thing could be slightly tricky to track down, given case problems etc. You can always ask here ;)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.