Q:

Java Divisional Error

Heres a snapshot my code:
int total = 2731;
String tmp = "I 1";
tmp = tmp.replaceAll("\\D", "");;
tmp = tmp.replaceAll("\\s+", "");;
int temp = Integer.parseInt(tmp);
double out = (double)temp / (double)total;
System.out.println(out);

This returns 3.661662394727206E-4 when by my calculations it should return
1.00/2731.00 = 0.00036616623
Can anybody tell me why this is the case?

A:

They're the same number:
0.0003 6616623
     3.661662394727206E-4

The E-4 bit means x 10-4 which means move the decimal point four places to the left.
If you were to output it instead with:
System.out.println(String.format("%.11f", out));

you would see that it's what you expected, albeit with proper rounding in the last position:
0.00036616624

To get a larger number of digits, just increase the precision specifier. For example, using %.19f gives:
0.0003661662394727206

