-1

iam allmoust done with my app but iam stuck on this thing , i have two int's called "positive" and "negative" and when i procces source below it shows 0.0

 total = positive + negative;
     float rate = positive/total;
     rate*=100;
     TextView analitycs = (TextView)v.findViewById(R.id.app_scores_analitycs);
     analitycs.setText(String.valueOf(rate));
Silvio Marijic
  • 483
  • 4
  • 12
  • 22

2 Answers2

1

Are positive and total floats/doubles?

If not, then an int/int will give you an int.

The solution would be to cast either positive or negative as a float.

try the following:

float rate = ((float)(positive))/total;
Victor KP
  • 437
  • 3
  • 10
1

What Victor said is true.

Also you might want to use something different than String.valueOf(rate) to set the text of your text view, because this method can give you an ugly representation of the number.

You should probably use String.format("%.2f", rate) ad tweak that to your needs.

Paul
  • 5,163
  • 3
  • 35
  • 43