Hello why when i doing division here i getting bad result. I have in array[0] 4 digits 3 4 5 1 result if 13 and doing division from 4 result need to 3.25 but getting 3.0 where i am doing mistake?
final long[] total = {0};
eventReference.child(eventId).child("EventRating").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
int rating = snapshot.child("rated").getValue(Integer.class);
total[0] = total[0] + rating;
}
}
double average = total[0] /dataSnapshot.getChildrenCount();
Toast.makeText(getContext(), average + " " + total[0], Toast.LENGTH_SHORT).show();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});