I have a float value in my code.
I wish to use multiple if else statements to check whether it is within the range (0,0.5) or (0.5,1) or (1.0,1.5) or (1.5,2.0). Please suggest a way for me to achieve this.
Earlier I thought, I can get the exact value of float. So, I was using the below mentioned code. But then I realised that it is not wise to use == clause for float variables. So, now I need to check whether the variable value is within a particular range.
float ratings=appCur.getFloat(appCur.getColumnIndexOrThrow(DbAdapter.KEY_ROWID));
if(ratings==0){
ivRate.setImageResource(R.drawable.star0);
}
else if(ratings==0.5){
ivRate.setImageResource(R.drawable.star0_haf);
}
else if(ratings==1){
ivRate.setImageResource(R.drawable.star1);
}
else if(ratings==1.5){
ivRate.setImageResource(R.drawable.star1_haf);
}
else if(ratings==2){
ivRate.setImageResource(R.drawable.star2);
}
1 Answer