I recently came up with a small issue in ios swift when converting Double to Int.
var myDoubleValue: Double = 10.2
var newInt = Int(myDoubleValue * 100) //1019
There I am multiplying 10.2 by 100 and NOT getting the expected value (1020) and instead 1019...
But works correct in most of the cases as follows
var myDoubleValue: Double = 10.3
var newInt = Int(myDoubleValue * 100) //1030
Also I further tested it with Java and the same issue there as well..
double myDoubleValue = 10.2;
int myIntValue1 = (int)(myDoubleValue * 100); //1019
I could overcome the issue by performing 'round' before convert to Int as follows...
var myDoubleValue: Double = 10.2
var newInt = Int(round(myDoubleValue * 100)) //1020
But this goes in to something I don't want if the value is having 3 decimal places as follows, because it's rounding at that time (10.206 ---> 1021)