Double multiplied by 100 and then cast to long is giving wrong value
- by xyz
I have the following code:
Double i=17.31;
long j=(long) (i*100);
System.out.println(j);
O/P : 1730 //Expected:1731
Double i=17.33;
long j=(long) (i*100);
System.out.println(j);
O/P : 1732 //Expected:1733
Double i=17.32;
long j=(long) (i*100);
System.out.println(j);
O/P : 1732 //Expected:1732{As expected}
Double i=15.33;
long j=(long) (i*100);
System.out.println(j);
O/P : 1533 //Expected:1533{as Expected}
I have tried to Google but unable to find reason.I am sorry if the question is trivial.