Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Double to Int
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
xHoly-Divinity




PostPosted: Thu Mar 08, 2007 5:30 pm   Post subject: Double to Int

I'm trying to do randomization, but I need to convert to an integer because Math.random() returns a double. I tried using .intValue(); but it is not wrking =S. So something along the lines of

int random = (Math.random()*10).intValue();

Ne1 help?
Sponsor
Sponsor
Sponsor
sponsor
OneOffDriveByPoster




PostPosted: Thu Mar 08, 2007 6:11 pm   Post subject: Re: Double to Int

xHoly-Divinity @ Thu Mar 08, 2007 5:30 pm wrote:
I'm trying to do randomization, but I need to convert to an integer because Math.random() returns a double. I tried using .intValue(); but it is not wrking =S. So something along the lines of

int random = (Math.random()*10).intValue();

Ne1 help?


Cast to int?

int random = (int)(Math.random() * 10);
xHoly-Divinity




PostPosted: Thu Mar 08, 2007 6:26 pm   Post subject: Re: Double to Int

Excellent Mr. Green
Thanks. Didn't know it was that simple
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: