我可以在Android上执行简单的除法和乘法吗

时间:2018-09-01 15:22:58

标签: android

我希望对检索到的数字进行计数,并找到其相对于fullAttendance int的百分比。这是我的代码:

attendanceButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            attendanceRef.whereEqualTo("sessionID", "5I0PLcpgmwdcjKLYLgkU").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {


                @Override
                public void onComplete(@NonNull Task<QuerySnapshot> task) {
                    if (task.isSuccessful()) {
                        int fullAttendance = 12;
                        int count = 0;
                        for (DocumentSnapshot document : task.getResult()) {
                            count++;
                            attendanceNumbs = findViewById(R.id.attendanceNums);
                            attendanceNumbs.setText((count/fullAttendance)*100 + " %" + "\n Attendance for this session");
                        }
                        Log.d("TAG", count + "");
                    } else {

                    }
                }
            });

1 个答案:

答案 0 :(得分:0)

fullAttendancecount变量都是整数,因此它们的除法结果也将是整数。您应将其中一个操作数声明为float(双精度),或将其中一个明确地强制除法,如下所示:

count/(float)fullAttendance