Re: How to get a double from the quotient of two int values?
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Tue, 16 Aug 2005 18:06:59 GMT
"Adam Funk" <a24061@xxxxxxxxx> wrote in message
news:ddsor4$31f2$1@xxxxxxxxxxxxxxxxxxxx
> 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?
Cast the integers to doubles.
y = (double)a / (double)b
- Oliver
.
- Follow-Ups:
- Re: How to get a double from the quotient of two int values?
- From: Adam Funk
- Re: How to get a double from the quotient of two int values?
- References:
- How to get a double from the quotient of two int values?
- From: Adam Funk
- How to get a double from the quotient of two int values?
- Prev by Date: Re: How to get a double from the quotient of two int values?
- Next by Date: Re: Using gtk with jre or sdk
- Previous by thread: Re: How to get a double from the quotient of two int values?
- Next by thread: Re: How to get a double from the quotient of two int values?
- Index(es):
Relevant Pages
|
|