[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

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

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
jbaird123
Asked:
jbaird123
  • 3
1 Solution
 
CEHJCommented:
Try
Integer i = new Integer((int).d.doubleValue());

Open in new window

0
 
CEHJCommented:
Oops
Integer i = new Integer((int)d.doubleValue());

Open in new window

0
 
jbaird123Author Commented:
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
 
CEHJCommented:
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.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now