Java Programming question - easy! (opinion based)

mcoski

Senior member
Oct 12, 1999
855
0
0
I need to calculate Miles Per Gallon of a trip. Basically taking user input of miles consumed, starting and ending mileage. The program works find, but my question is more of which variable type should I use. I converted all input strings to double to give a more precise answer but then the answer given in the end is long if it doesn't divide easily. Should I stick with what I have or go for integers all the way through?
 

jonmullen

Platinum Member
Jun 17, 2002
2,517
0
0
I would use double to work the problem and convert back to an integer for the answer.
 

tkdkid

Senior member
Oct 13, 2000
956
0
0
Use double all the way through, round the answer to 2 or 3 decimal places before displaying it to the user.
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
(use double all the way through, and control how you display the number)