Dawkins
asked on
Quick question about casting to doubles
Hi all quick Java newbie question,
With a calculation like this:
----------code------------ ---
int ten = 10;
int three = 3;
double out = ten / three;
----------/code----------- ----
out will equal 3. But if I cast *either* ten or three to a double , I get the correct result of 3.333333.
What is the correct thing to do? Cast both to double(which seems logical) or only one(which minimises the amount of casting)?
Or shouldn't I be getting into this situation in the first place?
With a calculation like this:
----------code------------
int ten = 10;
int three = 3;
double out = ten / three;
----------/code-----------
out will equal 3. But if I cast *either* ten or three to a double , I get the correct result of 3.333333.
What is the correct thing to do? Cast both to double(which seems logical) or only one(which minimises the amount of casting)?
Or shouldn't I be getting into this situation in the first place?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok thanks :)
;-)