I have the following code:
Double i=17.31;
long j=(long) (i*100);
System.out.println(j);
O/P : 1730 //Expected:1731
As has been explained, this is due to very small floating point precision.
This can be resolve via using a Math.round(), command, as follows:
long j=Math.round(i*100);
This will allow the program to compensate for the very small errors which are inherit using floating point calculations, by not using a floor operation, as the default (long) does.