Solved

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

Posted on 2011-09-29
4
417 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
by zero exception 10 83
Java string replace 11 77
ejb on wildfly 5 62
web project error add remove 1 79
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

732 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