If you explicitly cast either operand to a double you'll get the double
division operator and the other operand will be implicitly cast.
So:
x = (double) a / b;
or:
x = a / (double) b;
should do it but maybe the following shows exactly what you're doing?
x = (double) a / (double) b;
Obviously:
double a = 3;
would do the job too. It really depends what you're trying to achieve.
Regards,
John
"Adam Funk" <a2****@yahoo.com> wrote in message
news:dd***********@godfrey.mcc.ac.uk...
int a = 3;
int b = 7;
double x, y;
x = a / b;
y = (1.0 * a) / b;
System.out.println("x = " + x);
System.out.println("y = " + y);
produces
x = 0.0
y = 0.42857142857142855
I understand *why* x is 0.0 (the / operator returns an int, which is then
implicitly cast to a double).
But I'd like to know if "(1.0 * a) / b" is the correct way to get the
double
answer?
--
Thanks,
Adam