PDA

Click to See Complete Forum and Search --> : Simple DOuble to Integer Question.


TexasMd91
Apr 21st, 2007, 10:00 PM
int GambleCash = 1000;
double RandomGamble = Math.random();
int GambleReturnCash = (((GambleCash * 1.5) - (GambleCash / 2) + 1) * RandomGamble) +(GambleCash / 2);

And heres the error that i get.
http://img221.imageshack.us/img221/7597/compileerrorxq7.gif

Im guessing its because RandomGamble is a double which is needed for Math.random because its random 0 to 1 so its decimals which needs double.

so how can you change a double to an integer?

lunchboxtheman
Apr 21st, 2007, 10:41 PM
double value1 = 1.5;
int value = (int)value1;


value will be assigned the value of 1.
When you explicitly cast a double to an int the fractional part gets truncated.

TexasMd91
Apr 21st, 2007, 10:55 PM
it worked :!:!!:!:!: ty so much