I am posting two small codes. Both give different answers and I am not able to understand why this is happening and what is the work around of this problem.
i=3
a=i*0.1
a==0.3
FALSE
i=2
a=i*0.1
a==0.2
TRUE
I am posting two small codes. Both give different answers and I am not able to understand why this is happening and what is the work around of this problem.
i=3
a=i*0.1
a==0.3
FALSE
i=2
a=i*0.1
a==0.2
TRUE
You can round a, to get more consistent result:
i <- 3L
a <- i*0.1
round(a, 1) == 0.3
i=2L
a=i*0.1
round(a, 1) == 0.2
This may be occurring due to data type mis-match.