Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-11-2007, 12:14 AM
Member
 
Join Date: Dec 2007
Posts: 1
AlejandroPenton is on a distinguished road
transforming double to int
Hello guys! I want you to help me with something. I need to use the pow() method which can only be used with double data type. But I also need to use the result in a mod operation (%) which is only defined for int data type. So there must be a way to convert doubles to integers. Do you know how? thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-11-2007, 12:27 AM
Member
 
Join Date: Aug 2007
Posts: 30
dmacvittie is on a distinguished road
Hello Alejandro,

Try looking at Double.intValue() and Integer.doubleValue(). They should give you what you're looking for.

Don.
__________________
Don MacVittie F5 Networks -
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-11-2007, 02:34 AM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
Or you could always cast (although that is not as safe, since it can fail)
Code:
double d = 7.8; int i = (int) d;
note: that wont round. it will give you 7, although it should give you 8 (since we round up).
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Transforming XML to HTML Java Tip Java Tips 0 03-01-2008 11:06 PM
why does a variable be bracketted in double @val@!Thank you ibmzz Advanced Java 3 01-19-2008 09:38 AM
Calculating sin of a double value Java Tip Java Tips 0 01-13-2008 09:13 PM
Getting smallest possible Double value Java Tip Java Tips 0 12-06-2007 03:15 PM
How to round a double? Valeriano New To Java 1 05-31-2007 04:50 PM


All times are GMT +3. The time now is 10:14 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org