Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-11-2007, 12:14 AM
Member
 
Join Date: Dec 2007
Posts: 1
Rep Power: 0
AlejandroPenton is on a distinguished road
Default 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
  #2 (permalink)  
Old 12-11-2007, 12:27 AM
Member
 
Join Date: Aug 2007
Posts: 30
Rep Power: 0
dmacvittie is on a distinguished road
Default
Hello Alejandro,

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

Don.
__________________
Don MacVittie F5 Networks - DevCentral
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
Rep Power: 0
staykovmarin is on a distinguished road
Default
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
Reply

Bookmarks

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

BB 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 +2. The time now is 01:49 PM.



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