Computer Science Canada

Double to Int

Author:  xHoly-Divinity [ 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?

Author:  OneOffDriveByPoster [ 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);

Author:  xHoly-Divinity [ Thu Mar 08, 2007 6:26 pm ]
Post subject:  Re: Double to Int

Excellent Mr. Green
Thanks. Didn't know it was that simple


: