• Status: Solved
• Priority: Medium
• Security: Public
• Views: 212

# 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?
0
Dawkins
• 2
1 Solution

Commented:
I always cast both...

it doesn't matter

if you cast one, then it automagically casts the other one (to make it up to the same bit length as the larger one)

doing both yourself, just makes it a bit more obvious...

I guess it's down to persona preference :-)

Tim
0

Commented:
persona = personal

;-)
0

Author Commented:
ok thanks :)
0

## Featured Post

• 2
Tackle projects and never again get stuck behind a technical roadblock.