|
|
Re: how do you change an integer into a double?
|
Posted: Mar 6, 2006 5:13 AM
|
|
You need to convert at least one of the numbers to a double value BEFORE the division.
The operator '/' means DIV, if both operators are integers ('%' would be the rest). If one of the operators is a double, the other operator get's converted into double, too. After that, a floating point division will be executed.
If you use variables, this would be valid
double result = a / (double)b;
I don't know if this would work
double result = (double)a/b;
Use this form instead:
double result = ((double)a)/b;
If you use constats, you can also do this:
double result = 1 / 4.0;
or
double result = 1 / 4d;
|
|