[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2011-09-29
4
Medium Priority
?
446 Views
Last Modified: 2012-05-12
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.
0
Comment
Question by:jbaird123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 36818601
Try
Integer i = new Integer((int).d.doubleValue());

Open in new window

0
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 36818604
Oops
Integer i = new Integer((int)d.doubleValue());

Open in new window

0
 

Author Closing Comment

by:jbaird123
ID: 36818614
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 36818632
That kind of thing could be slightly tricky to track down, given case problems etc. You can always ask here ;)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question