Solved

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

Posted on 2011-09-29
4
377 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
  • 3
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Try
Integer i = new Integer((int).d.doubleValue());

Open in new window

0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
Comment Utility
Oops
Integer i = new Integer((int)d.doubleValue());

Open in new window

0
 

Author Closing Comment

by:jbaird123
Comment Utility
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
Comment Utility
That kind of thing could be slightly tricky to track down, given case problems etc. You can always ask here ;)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now