
-----------------------------------
xHoly-Divinity
Thu Mar 08, 2007 5:30 pm

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?

-----------------------------------
OneOffDriveByPoster
Thu Mar 08, 2007 6:11 pm

Re: 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?

Cast to int?

int random = (int)(Math.random() * 10);

-----------------------------------
xHoly-Divinity
Thu Mar 08, 2007 6:26 pm

Re: Double to Int
-----------------------------------
Excellent :mrgreen: 
Thanks. Didn't know it was that simple
