Solved

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

Posted on 2011-09-29
4
411 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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
xampp tool 12 58
login jsp example 24 85
eclipse buid path vs tomcat lib path 10 37
Java Restore security prompts not working 10 120
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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

740 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