Solved

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

Posted on 2011-09-29
4
404 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
ID: 36818601
Try
Integer i = new Integer((int).d.doubleValue());

Open in new window

0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
fibonacci ten numbers 4 45
ejb example issues 3 26
Facing this issue for maven proxy setting 2 20
eclipse console opening separately 2 29
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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 learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

860 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