我正在尝试做一些简单的百分比,而我的结果总是为零。
String taste = jsonArray.getJSONObject(i).getString("taste");
String rate = jsonArray.getJSONObject(i).getString("rate");
Log.d("taste", rate);
int rateNum = Integer.parseInt(rate);
Log.d("taste", "rateNum is " + rateNum);
int percent = rateNum / count;
percent = percent * 100;
Log.d("taste", "percent is " + percent);
奇怪的是查看我的日志,我的 rateNum 和计数变量都是数字而不是零:
06-26 21:52:44.319: D/taste(11812): count it:20
06-26 21:52:44.319: D/taste(11812): 13
06-26 21:52:44.319: D/taste(11812): rateNum is 13
06-26 21:52:44.319: D/taste(11812): percent is 0
06-26 21:52:44.319: D/taste(11812): 3
06-26 21:52:44.319: D/taste(11812): rateNum is 3
06-26 21:52:44.319: D/taste(11812): percent is 0
06-26 21:52:44.319: D/taste(11812): 3
06-26 21:52:44.319: D/taste(11812): rateNum is 3
06-26 21:52:44.319: D/taste(11812): percent is 0
06-26 21:52:44.319: D/taste(11812): 1
06-26 21:52:44.319: D/taste(11812): rateNum is 1
06-26 21:52:44.319: D/taste(11812): percent is 0
所以我不知道为什么我的百分比总是为零。